My dataset contains two columns with data that are offset - something like:
col1<-c("a", "b", "c", "d", "ND", "ND", "ND", "ND")
col2<-c("ND", "ND", "ND", "ND", "e", "f", "g", "h")
dataset<-data.frame(cbind(col1, col2))
I would like to combine those two offset columns into a single column that contains the letters a through h and nothing else.
Something like the following is what I'm thinking, but rbind is not the right command:
dataset$combine<-rbind(dataset$col1[1:4], dataset$col2[5:8])
What about:
sel2 <- col2!="ND"
col1[sel2] <- col2[sel2]
> col1
[1] "a" "b" "c" "d" "e" "f" "g" "h"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With