[R] Indexing Question

Roger D. Peng rpeng at jhsph.edu
Thu Oct 9 21:12:29 CEST 2003


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
>




More information about the R-help mailing list