[R] sampling rows from a list
Bert Gunter
gunter.berton at gene.com
Mon Apr 2 22:29:00 CEST 2012
??
Something like:
lapply(mydata, function(x){
nr <- nrow(x)
x[sample(seq_len(nr),nr,rep=TRUE),]
})
maybe. The idea is to use the sampled rows as your row index.
-- Bert
On Mon, Apr 2, 2012 at 11:24 AM, Bcampbell99 <BrianD.Campbell at ec.gc.ca> wrote:
> Hi:
>
> I'm sure this seems like a rudimentary question, but I am not well versed
> with R syntax for lists. I have a ragged array from which I've removed
> records (entire rows) with missing data. The functions I used to remove the
> missing cases resulted in the generation of an R list class object, that
> looks something like this;
>
> mydata
> [[1]]
> [,1] [,2] [,3]
> [1,] 1 2 3
> [2,] 4 5 6
> [3,] 7 8 9
>
> [[2]]
> [,1] [,2] [,3]
> [1,] 10 11 12
> [2,] 13 14 15
>
> [[3]]
> [,1] [,2] [,3]
> [1,] 16 17 18
> [2,] 19 20 21
> [3,] 22 23 24
> [4,] 25 26 27
> [5,] 28 29 30
>
> Part1
> What I would like to do is draw an equal number of random row samples
> from[[1]],[[2]] and [[3]] (to preserve the structure of [,1][,2],[,3].
>
> Part2
> Then I would like to cocerce the list object into something like an array.
>
> Help scripting out part 1 or 2 would be much appreciated.
>
> Brian Campbell
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/sampling-rows-from-a-list-tp4526831p4526831.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.
--
Bert Gunter
Genentech Nonclinical Biostatistics
Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
More information about the R-help
mailing list