[R] Lists into matrices within lists...again

ewaters ewaters at nchecr.unsw.edu.au
Tue Feb 23 03:27:05 CET 2010


Related questions to this have been asked before, but I have tried all
options they gave me unsuccessfully (do.call and unlist).

I start with three lists of summary statistics,  100 elements each, which I
bind together:

statslist <- as.data.frame(cbind (means, vars, mcrs))

I then take 100 samples of this data frame of varying lengths:

stats <- lapply (1:100, function (dummy) {
statslist[sample(nrow(statslist), (sample (10:20, 1, replace = TRUE)),
replace = TRUE),]})

It returns basically what I want:

> stats[[i]]
     means      vars        mcrs
71    1.81  3.832222     2.92725
9     2.56  8.127677    4.734874
91    3.44   9.66303     5.24902
68    0.14 0.1216162 0.008686869

except that:

> is.list(stats[[i]]$means)
[1] TRUE

I don't want this to be a list, because I want to do regressions using the
variable which are in columns, which apparently R won't do if they are in
lists.

I have tried every possible combination of working with do.call, rbind,
as.data.frame, etc to get this into matrix form to no avail.

I have also tried using sapply instead of lapply, but that returns vectors
which again, R doesn't want to do regression on.

Any tips would be very much appreciated, been going around in circles for a
while here.

Edward Waters
PhD Student UNSW


-- 
View this message in context: http://n4.nabble.com/Lists-into-matrices-within-lists-again-tp1565433p1565433.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list