I am working in R and am trying to take a dataframe with 7 columns and create a 2 column dataframe with all the combinations of each row's responses stacked on top of each other.
For example if I had:
1,0,1,0
I would want to transform that row to the rows
1,0
1,1
1,0
0,1
0,0
1,0
And do that to every row in the dataframe and stack them.
I know how to do this for 1 row at a time
df2<-combn(df[1,],2)
That code will get me the combinations of one row like my example above; however I can't figure out how to do apply it to all rows. My best guess would be something along the lines of
df3<-apply(1:nrow(df), 1, function(x) combn(df[x,],2))
However I am getting the "dim(x) must have a positive length" error. Does anyone know what my problem is and can explain what I am doing wrong and why I need to do it a certain way. New to coding R beyond base functions. As far as data goes it's just binary data.