[R] sapply( ) a loop function

2011-08-11 Thread Sean Bignami
Hello R-universe... I am having trouble writing a function which contains a loop so I can sapply() it to a list of data frames Each data frame has 241 observations of 15 variables. My loop takes a random sample of one row until the 40 consecutive rows after the sample have a d2p(variable) sum

Re: [R] sapply( ) a loop function

2011-08-11 Thread Daniel Malter
I am not sure what purpose the while loop has. However, the main problem seems to be that you need to put: i-sample(1:(n-40),1) #This sample from 1 to n-40 rather than i-sample(1:n-40,1) #this samples one 1:n and then subtracts 40 Otherwise, you may get negative index values Best, Daniel

Re: [R] sapply( ) a loop function

2011-08-11 Thread Dennis Murphy
Hi: samp_func() doesn't return anything. Either (1) type test as the last line of the function body or (2) don't assign the last sum to an object. HTH, Dennis On Thu, Aug 11, 2011 at 1:59 PM, Sean Bignami bignam...@gmail.com wrote: Hello R-universe... I am having trouble writing a function

Re: [R] sapply( ) a loop function

2011-08-11 Thread R. Michael Weylandt
The previous two posters basically covered everything, but since I'm on the train with not too much to do, here's a more detailed response building on what they said. The following code is shovel-ready and can be pasted directly to your command line if you have your main data frame called d