Re: [R] Help me replace a for loop with an "apply" function

2009-10-01 Thread jim holtman
What I am doing is trying to determine where the dates are not sequential (difference is not one day). Everytime that this occurs, the expression 'diff(.days) != 1' is TRUE and this is where a new sequence starts. 'diff' will return a vector one shorter than its input; I am assuming that the firs

Re: [R] Help me replace a for loop with an "apply" function

2009-10-01 Thread gd047
Congratulations! Could you explain to me the reason you add an initial "TRUE" value in the cumulatice sum? jholtman wrote: > > Will this work: > >> x <- read.table(textConnection(" day user_id > + 2008/11/012001 > + 2008/11/012002 > + 2008/11/012003 > + 2008/11/0120

Re: [R] Help me replace a for loop with an "apply" function

2009-10-01 Thread jim holtman
Will this work: > x <- read.table(textConnection(" day user_id + 2008/11/012001 + 2008/11/012002 + 2008/11/012003 + 2008/11/012004 + 2008/11/012005 + 2008/11/022001 + 2008/11/022005 + 2008/11/032001 + 2008/11/032003 + 2008/11/032004 + 2008/11/03

[R] Help me replace a for loop with an "apply" function

2009-10-01 Thread gd047
...if that is possible My task is to find the longest streak of continuous days a user participated in a game. Instead of writing an sql function, I chose to use the R's rle function, to get the longest streaks and then update my db table with the results. The (attached) dataframe is somethin