[R] Paste every two columns together

JSHuang js.huang at protective.com
Thu Jan 29 02:16:54 CET 2015


Hi, 

  Here is my implementation:

> combine <- function(x){
+ odd <- x[1:length(x) %% 2 == 1]
+ even <- x[1:length(x) %%2 == 0]
+ paste0(odd,even)}
> temp <- letters[1:24]
> temp
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r"
"s" "t" "u" "v" "w" "x"
> combine(temp)
 [1] "ab" "cd" "ef" "gh" "ij" "kl" "mn" "op" "qr" "st" "uv" "wx"



--
View this message in context: http://r.789695.n4.nabble.com/Paste-every-two-columns-together-tp4702429p4702433.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list