[R] Lists into matrices within lists...again
Peter Alspach
Peter.Alspach at plantandfood.co.nz
Tue Feb 23 04:56:09 CET 2010
Tena koe Edward
It is difficult to know the best approach from the information supplied,
but using unlist() at the appropriate place in your code, maybe
unlist(stats[[i]]$means), will probably get you where you want to be.
HTH .....
Peter Alspach
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of ewaters
> Sent: Tuesday, 23 February 2010 3:27 p.m.
> To: r-help at r-project.org
> Subject: [R] Lists into matrices within lists...again
>
>
> 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-tp
> 1565433p1565433.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list