Skip to content
Prev 374673 / 398513 Next

Split a data.frame

Hi!

How about this:

--- snip --

for (i in 1:(length(split_str)-1)) {
????assign(paste("DF",i,sep=""),DF[
c((which(DF$name==split_str[i])+1):(which(DF$name==split_str[i+1])-1)), 
])
}

--- snip ---

'assign' creates for each subset a new data.frame DFn, where n ist a
count (1,2,...).

But note: if your DF has duplicates in 'name' (e.g. two rows with 'a'
in 'DF$name'), my solution will use the first occurrence only (and this
for both start and for end).

HTH,
Kimmo
2018-05-19 kello 16:37 +0530, Christofer Bogaso wrote: