The following is dataset, I need to make two.
ID <- 1:4
pos <- c(0, 245, 567, 871)
A1 <- c("A/B", "A/A", "B/B", "A/A")
B1 <- c("B/B", "C/C", "C/B", "D/A")
C1 <- c("B/B", "C/C", "-/-", "D/A")
mydf2 <- data.frame (ID, A1, B1, C1, pos)
I are interested to have 2:4 column in one dataset
mydf3 <- mydf2[,2:4]
Now I want rest of variables in different dataframe.
mydf4 <- mydf2[, names(mydf2) != names(mydf3)]
Am I missing something obvious ?
Warning message:
In names(mydf2) != names(mydf3) :
longer object length is not a multiple of shorter object length
You want instead:
You got the error message you did because the
!=operator performs an elementwise comparison of its two vector arguments. When the vectors have different lengths, it recycles the shorter one to fill it out to the length of the longer one. You passed it vectors of length 3 and 5, and since neither number is a divisor of the other, it had an inkling that you might not actually be wanting that recycling behavior and warned you about what it was doing. (Compare the results of2:4 != 1:6to2:4 != 1:5to see how this could have been even more puzzling to debug.)