I have the following data frame:
Step 1 2 3
1 5 10 6
2 5 11 5
3 5 13 9
4 5 15 10
5 13 18 10
6 15 20 10
7 17 23 10
8 19 25 10
9 21 27 13
10 23 30 7
I would like to retrieve the columns that satisfy one of the following conditions: if step 1 = step 4 or step 4 = step 8. In this case, column 1 and 3 should be retrieved. Column 1 because the value at Step 1 = value at step 4 (i.e., 5), and for column 3, the value at step 4 = value at step 8 (i.e., 10).
I don't know how to do that in R. Can someone help me please?
step1 = step 4Is that values in column 'step' equal to other column? or is it the duplicate elements?df1[sapply(df1, function(x) max(rle(x)$lengths)>=4),]df1[sapply(df1, function(x) length(unique(x[1:4])) == 1 | length(unique(x[4:8]))),]