[R] Need help locating the longest series of consecutive numbers in a matrix
Staples, Angela Dawn
adstaple at indiana.edu
Wed Oct 28 17:27:09 CET 2009
I need to determine the length of the longest series of consecutive numbers
(1's to be specific) and the start time of that series. For example, in the
following sample, the first column is "time" and the second column indicates
the presence of the target behavior.
I would like a function that would return "21" as the start time and "17" as
the length.
sample <-
matrix(data=c(1:40,rep(0,10),rep(1,3),rep(0,3),1,0,1,0,rep(1,17),0,0,0),40,2
)
I would appreciate any suggestions you have.
Respectfully,
~ Angela
More information about the R-help
mailing list