I would use data.table
to give the rows id's for each subset.
require(data.table)
dt <- data.table(all_data)
dt[which.min(sec):nrow(dt), id:=1:.N, by=sec]
Then you can continue to split as you did:
count <- 1:dt[, max(id, na.rm=TRUE)]
eq = paste("subd", count," = data.frame(dt[id==", count, ",list(sec, data, data2)])", sep = "")
eval(parse(text = eq))
Alternatively, and more common in R, you can use split
to split into subsets. This will return a list
of data.frames
. That's very useful, since you can then use lapply
to evaluate a function (curve fitting, etc.) on all data.frames
simultaneously.
split(data.frame(dt[, list(sec, data, data2)]), dt$id)