I just found an answer for you in the new R wiki
(http://wiki.r-project.org) with a subject, "Grab an item from each of
several matrices in a list"
(http://wiki.r-project.org/rwiki/doku.php?id=tips:data-lists:items_from_list&s=lapply):
Let Z denote the list of matrices. All matrices have the same order.
Suppose you need to take element [1, 2] from each.
lapply(Z, function(x) x[1, 2])
should do this, giving a list. Use sapply() if you want a vector. (Brian
Ripley)
I believe I learned this from Venables and Ripley (2002) Modern
Applied Statistics with S, 4th ed. (Springer, esp. p. 330.
Hope this helps.
Spencer Graves
Roberts, J. Kyle wrote:
Dear All,
I want to correlated the predicted values from a "lme" run, and the
original outcome values from the original dataset. The caveat is that I
want to do it honoring the grouping structure.
So far, I have done this:
new<-split(data.frame(my.data$outcome, predict(lme.out)), my.data$group)
new.2<-lapply(new, cor)
The problem is that I now have a list in which each part of the list has
the following:
$"1":
X1 X2
X1 1.0000000 0.9327732
X2 0.9327732 1.0000000
$"2":
X1 X2
X1 1.0000000 0.9449112
X2 0.9449112 1.0000000
. . . etc.
So here's my question: How do I just get the correlation between the
two variables and not have a correlation matrix? The reason that I ask
is because I will need to then unlist these correlations to include in
another function I have built.
Thanks for the help,
Kyle
***************************************
J. Kyle Roberts, Ph.D.
Baylor College of Medicine
Center for Educational Outreach
One Baylor Plaza, MS: BCM411
Houston, TX 77030-3411
713-798-6672 - 713-798-8201 Fax
jkrobert@bcm.edu <mailto:jkrobert@bcm.edu>
***************************************
|