in the next frame. I want to hold rows only once if they have duplicate pairs (1 4 and 4 1 are considered the same pair) Var1and Var2. I thought about sorting Var1and Var2in a row, and then removing duplicate rows based on both Var1, and Var2. However, I do not get the desired result.
Here's what my data looks like:
Var1 <- c(1,2,3,4,5,5)
Var2 <- c(4,3,2,1,5,5)
f <- c("blue","green","yellow","red","orange2","grey")
g <- c("blue","green","yellow","red","orange1","grey")
testdata <- data.frame(Var1,Var2,f,g)
I can sort inside the rows, however the values ββof the columns f and g should remain intact, how to do this?
testdata <- t(apply(testdata, 1, function(x) x[order(x)]))
testdata <- as.data.table(testdata)
Then I want to remove duplicate rows based on Var1andVar2
I want to get this as a result:
Var1 Var2 f g
1 4 blue blue
2 3 green green
5 5 orange2 orange1
Thank you for your help!