I'm aware that this question is simple, but couldn't find a solution without creating step objects, and I want a one-line code, or one as simplest as it could be.
Suppose I have a data frame called df with columns x, y, z:
x<-c(rep('place1',33),rep('place2',33),rep('place3',34))
y<-sample(c('type1','type2','type3','type4','type5'),100,replace=T)
z<-sample(40:80,100,replace=T)
df<-data.frame(x,y,z)
I would like to get all subsets possible of z for each combination of levels of x and y (type1 in place1, type2 in place1, type3 in place1...type4 in place3 and type5 in place3). Something like this:
[[place1]]
[type1]
[1] 57 73 74 47 52 61
[type2]
[1] 72 76 64 62 73 75
...
[type5]
...
[[place3]]
[type1]
...
[type5]
In the case this is possible, how could I access each subset?
I've tried a nested split
inside an lapply
, without success.
Sorry for this simple question, but couldn't find a suitable solution.
Any help would be appreciated.