This code transforms a vector of nucleotides into a coded version with numbers from 1 to 4. However, I'd like something a bit more elegant, possibly in a single line. Is this possible?
vector2 <- c("c","a","g","g","c","g","g","g","a","t","t","t","c","t","c","t","t","g","t","t","g","a","c","a","g", "a","a","t","c","c")
vector2[vector2=="a"]<-1
vector2[vector2=="c"]<-2
vector2[vector2=="g"]<-3
vector2[vector2=="t"]<-4
as.numeric(vector2)
Thanks