Skip to content
Prev 374670 / 398513 Next

Split a data.frame

DF = data.frame(name = c('a', 'v', 'c'), val = 0); DF
##   name val
## 1    a   0
## 2    v   0
## 3    c   0
split_str = c('a', 'c')
# If we assume that the values in split_str are ordered in the same order
as in the dataframe, then this might work.

offsets <- match(split_str, DF$name)
# Since you only want the rows in between

DF[diff(offsets), ]
##   name val
## 2    v   0


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
On Sat, May 19, 2018 at 7:58 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote: