Skip to content
Prev 374669 / 398513 Next

Split a data.frame

Hello,

Maybe something like the following.

splitDF <- function(data, col, s){
     n <- nrow(data)
     inx <- which(data[[col]] %in% s)
     lapply(seq_along(inx), function(i){
         k <- if(inx[i] < n) (inx[i] + 1):(inx[i + 1])
         data[k, ]
     })
}

splitDF(DF, "name", split_str)


Hope this helps,

Rui Barradas
On 5/19/2018 12:07 PM, Christofer Bogaso wrote: