I wonder how to split my data below such that I get a list of smaller dataf.rames each of which containing a unique pair of type in it?
My desired_output is shown below.
Note that this is just a toy data, so type can be any other variable. Also, note that if a particular type has just one row (like type == 4), I want to exclude that with a warning that says:
type 4 has just one row thus is excluded.
m=
"
obs type
1 1
2 1
3 a
4 a
5 3
6 3
7 4
"
data <- read.table(text = m, h=T)
desired_output <-list(
data.frame(obs=1:4, type=c(1,1,"a","a")),
data.frame(obs=c(1,2,5,6), type=c(1,1,3,3)),
data.frame(obs=3:6, type=c("a","a",3,3))
)
# warning: type 4 has just one row thus is excluded.