search for: rle_tabl

Displaying 1 result from an estimated 1 matches for "rle_tabl".

Did you mean: rle_table
2009 Oct 01
1
Help me replace a for loop with an "apply" function
...2008/11/03 2003 2008/11/03 2004 2008/11/03 2005 2008/11/04 2001 2008/11/04 2003 2008/11/04 2004 2008/11/04 2005 --- R code follows ------------------------------------------------------ # turn it to a contingency table my_table <- table(user_id, day) # get the streaks rle_table <- apply(my_table,1,rle) # verify the longest streak of "1"s for user 2001 # as.vector(tapply(rle_table$'2001'$lengths, rle_table$'2001'$values, max)["1"]) # loop to get the results # initiate results matrix res<-matrix(nrow=dim(my_table)[1], ncol=2) fo...