Re: [R] How to extract diagonals

From: Birgit Lemcke <birgit.lemcke_at_systbot.uzh.ch>
Date: Wed, 20 Jun 2007 15:09:04 +0200

Hello Gavin and thanks for your answer.

Your completely right I don´t need the diagonal that is the bisecting line of the angle.

I need another diagonal of the (now) matrix.

         A1 A2 A3 A4 B1 B2 B3 B4
    A1
    A2
    A3
    A4
    B1 X

    B2       X
    B3            X
    B4                 X


I need for example the diagonal that compares A1 with B1. Do you have an idea how I can handle this?

What is the effect of this code?

all.equal(diags, diag(as.matrix(dis.bc)))

Thanks a lot and sorry for my inability to solve my problems on my own.

Am 20.06.2007 um 14:11 schrieb Gavin Simpson:

> On Wed, 2007-06-20 at 13:26 +0200, Birgit Lemcke wrote:
>> Hello,
>>
>> I am using Mac OS X on a power book and R 2.5.0
>>
>> I try to extract a diagonal from a dissimilarity matrix made with
>> dsvdis, with this code:
>>
>> diag(DiTestRR)
>>
>> But I get this error message:
>>
>> Fehler in array(0, c(n, p)) : 'dim' spezifiziert ein zu groes Array
>>
>> english:
>>
>> Error in array(0, c(n, p)) : 'dim' specifies a too big array.
>>
>> Is there a limit to extract diagonals?
>
> The returned object is not a matrix, but an object of class "dist"
> which
> doesn't store the diagonals or the upper triangle of the dissimilarity
> matrix to save memory. You need to convert the dist object to a matrix
> first, then extract the diagonal. But, as this shows:
>
>> require(labdsv)
>> ?dsvdis
>> data(bryceveg)
>> ?dsvdis
>> dis.bc <- dsvdis(bryceveg,index="bray/curtis")
> Warning in symbol.For("dsvdis") : 'symbol.For' is not needed: please
> remove it
>> diag(as.matrix(dis.bc))
>
> This is meaningless as the diagonals are all zero, as they should be;
> this is the distance between a site and itself.
>
>>
>> I hope somebody will help me!
>
> So perhaps you could explain why you want the diagonal. It would be
> easier to just do:
>
> diags <- rep(0, length = nrow(bryceveg))
>
> That will be without the sample labels, but that is easily rectified
>
>> names(diags) <- rownames(bryceveg)
>> all.equal(diags, diag(as.matrix(dis.bc)))
> [1] TRUE
>
> So you'll have to reformulate your question if this is not what you
> wanted.
>
> A word of warning, do not do diag(dis.bc)) on the above as it
> brought my
> Linux box to it's knees trying to do something silly - easily
> recoverable, but beware.
>
> HTH
>
> G
>
>>
>> Greetings
>>
>> Birgit Lemcke
>
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> Gavin Simpson [t] +44 (0)20 7679 0522
> ECRC, UCL Geography, [f] +44 (0)20 7679 0565
> Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
> Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
> UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>

Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
birgit.lemcke_at_systbot.uzh.ch

        [[alternative HTML version deleted]]



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 20 Jun 2007 - 13:19:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jun 2007 - 16:32:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.