I want to extract a data frame using a formula that determines which columns to select, and some intersect between columns .
I know the function model.frame . However, it does not give me transitions:
For instance:
df <- data.frame(x = c(1,2,3,4), y = c(2,3,4,7), z = c(5,6, 9, 1)) f <- formula('z~x*y') model.frame(f, df)
exit:
> df xyz 1 1 2 5 2 2 3 6 3 3 4 9 4 4 7 1 > f <- formula('z~x*y') > model.frame(f, df) zxy 1 5 1 2 2 6 2 3 3 9 3 4 4 1 4 7
I hope to get:
zxyx*y 1 5 1 2 2 2 6 2 3 6 3 9 3 4 12 4 1 4 7 28
Is there a package that could achieve this functionality? (It would be ideal if I could get the resulting matrix as a sparse matrix , because the crossed columns will be very sparse)
source share