I have an indexing question. I have a data set that looks like this:>b[[1]] [1] 22 23 24 25 26 [[2]] [1] 6 7 8 9 NA etc. from [[1]] to [[1000]] Then I need to use the sample function to take two samples from b[[1]] to b[[1000]] each separately. I thought something like "sample(na.omit(b[[1:1000]]),2,replace=TRUE)" would work but it doesn't. Is there a way to index this properly?? Thanks, Nathan _________________________________________________________________ Add MSN 8 Internet Software to your existing Internet access and enjoy patented spam protection and more. Sign up now!
"Nathan Cooper" <nathanwands at hotmail.com> writes:> I have an indexing question. I have a data set that looks like this: > > >b > [[1]] > [1] 22 23 24 25 26 > > [[2]] > [1] 6 7 8 9 NA > > etc. from [[1]] to [[1000]] > > Then I need to use the sample function to take two samples from b[[1]] > to b[[1000]] each separately. I thought something like > "sample(na.omit(b[[1:1000]]),2,replace=TRUE)" would work but it > doesn't. Is there a way to index this properly?? Thanks,Not really. I'd try lapply(lapply(b,na.omit),sample,2,replace=TRUE) or lapply(b,function(x)sample(na.omit(x),2,replace=TRUE)) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
I think what you want is lapply(b, function(x) sample(na.omit(x), 2, replace = TRUE)) -roger Nathan Cooper wrote:> I have an indexing question. I have a data set that looks like this: > >> b > > [[1]] > [1] 22 23 24 25 26 > > [[2]] > [1] 6 7 8 9 NA > > etc. from [[1]] to [[1000]] > > Then I need to use the sample function to take two samples from b[[1]] > to b[[1000]] each separately. I thought something like > "sample(na.omit(b[[1:1000]]),2,replace=TRUE)" would work but it > doesn't. Is there a way to index this properly?? Thanks, > > Nathan > > _________________________________________________________________ > Add MSN 8 Internet Software to your existing Internet access and enjoy > patented spam protection and more. Sign up now! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >