[R] A programming question - is what I want to do possible in R?

ewaters ewaters at nchecr.unsw.edu.au
Tue Sep 29 03:39:12 CEST 2009


Thanks for your help.

Unfortunately when I try it this generates an error as follows:

> randomSamples<-lapply(1:2000,function(){
+ meta_comp[sample(nrow(meta_comp),nTimes),]})
Error in FUN(1:2000[[1L]], ...) : unused argument(s) (1:2000[[1]])




jholtman wrote:
> 
> nTime <- 15  # how many samples to take
> randomSamples <- lapply(1:2000, function(){
>     largeDF[sample(nrow(largeDF), nTimes),]
> })
> 
> This will create a list of 2000 dataframes with the samples
> 
> On Sun, Sep 27, 2009 at 10:45 PM, ewaters <ewaters at nchecr.unsw.edu.au>
> wrote:
>>
>> I have a large data frame, 77 rows, with 10 columns. Each row represents
>> a
>> unique individual with 10 characteristics, some of which are categorical
>> factors and some continuous numeric variables. Each of the ten variables
>> is
>> important (the 10 columns obviously correspond to the individuals of
>> interest). Importantly, this data set represents a population (not
>> sample)
>> of people with a certain medical condition.
>>
>> What I want to do is to select 2000 random samples of between 2 and 24
>> individuals, preserving all the information.
>>
>> I can easily write loops that will sample from 1:77 2 - 24 times, what I
>> really want to know is there any way to easily link the output of loops
>> like
>> that to the data set so I don't have to trawl through and do it manually
>> 2000 times?
>>
>> Any advice on whether I should even attempt that in R, or try some sort
>> of
>> hash table in C or somewhere, would be appreciated.
>> --
>> View this message in context:
>> http://www.nabble.com/A-programming-question---is-what-I-want-to-do-possible-in-R--tp25639955p25639955.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.
>>
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem that you are trying to solve?
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/A-programming-question---is-what-I-want-to-do-possible-in-R--tp25639955p25655666.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list