Skip to content
Prev 321891 / 398500 Next

dividing a long column to many short ones by a condition

Hello,

Sorry, forgot the instruction to read in the data.
Now the complete code.


x <- scan(text = "
90.1194354
87.94788274
80.34744843
64.06080347
30.40173724
0
0
0
0
0
16.28664495
23.88707926
29.31596091
48.85993485
13.02931596
0
0
0
7.600434311
20.62975027
29.31596091
32.5732899
")
x

grp <- cumsum(abs(c(0, diff(x == 0))))
tmp <- lapply(split(x, grp), function(x) if(all(x == 0)) NULL else x)
tmp[sapply(tmp, function(x) !is.null(x))]



Rui Barradas

Em 18-04-2013 12:24, Rui Barradas escreveu: