split dataframe in R by row

It sounds like you want two data frames, where one has (A,B,C) in it and one has just D. In that case you could do

Data1 <- subset(Data, group %in% c("A","B","C"))
Data2 <- subset(Data, group=="D")

Correct me if you were asking something different


For those who end up here through internet search engines time after time, the answer to the question in the title is:

x <- data.frame(num = 1:26, let = letters, LET = LETTERS)

split(x, sort(as.numeric(rownames(x))))

Assuming that your data frame has numerically ordered row names. Also split(x, rownames(x)) works, but the result is rearranged.

Tags:

R