[R] Substituting elements in vector

JS Huang js.huang at protective.com
Tue Feb 17 23:45:10 CET 2015


Hi,

  Here is an implementation.

> my.vector
[1] "A" "B" "C" "D" "E" "F" "G"
> vec1
[1] "p" "q" "r" "s" "t"
> vec2
[1] "x" "y" "z"
> final <- as.character(unlist(sapply(my.vector,function(x)
> if(x=="B"){vec1}else{if(x=="E"){vec2}else{x}})))
> final
 [1] "A" "p" "q" "r" "s" "t" "C" "D" "x" "y" "z" "F" "G"



--
View this message in context: http://r.789695.n4.nabble.com/Substituting-elements-in-vector-tp4703395p4703431.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list