Skip to content

extracting one element of correlation matrices from a list poroduced by the 'by' statement

1 message · Mohammad A. Chaudhary

#
Great! Thank you very much. Looks R has unlimited possibilities.
Regards,
Ashraf

-----Original Message-----
From: pd at pubhealth.ku.dk [mailto:pd at pubhealth.ku.dk] On Behalf Of Peter
Dalgaard
Sent: Wednesday, April 13, 2005 4:11 PM
To: Mohammad A. Chaudhary
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] extracting one element of correlation matrices from a
list poroduced by the 'by' statement

"Mohammad A. Chaudhary" <mchaudha at jhsph.edu> writes:
a
.....
One way could be 

 sapply(by(d1[2:3],d1[,1],cor),"[",1,2)

another is 

 by(d1[2:3],d1[,1],function(f)cor(f)[1,2])

or, (this possibility never occurred to me before)

 by(d1[2:3],d1[,1], with, cor(c,e))


You might want to wrap the last two in a c() construct but they
actually are vectors already, they just don't look it when print.by
has done its work.