Entering edit mode
6.8 years ago
mail2steff
▴
70
I am new to R programming. I have a data frame with 120 columns and 518 rows. Now I have to compare columns to columns (2 at once). If two values in successive columns are same 0 ( if not same -> 1) should be added to a new data frame
>data
V1 V2 V3 V4 V5 V6
A A C C G G
A G T T C G
G C T A A C
The output should look like
>new_data_fram
V12 V34 V45
0 0 0
1 0 1
1 1 1
Can anyone help me with this? Thank you in advance
You're skipping a cpl of cols in your output example. Did you try any code in R? If so, show it along with any errors. If not, try something and come back with it.
I tried with combn fucntion in R.
compare = t(combn(ncol(file8),2,FUN=function(x)file8[,x[1]]==file8[,x[2]]))
But I got the following output1 1 1 1 1 1
0 0 0 0 0 0
0 0 0 0 0 0