Re: [R] Substring a column vector

2011-07-06 Thread Dennis Murphy
Hi: Here's one take: shalve <- function(x) { nc <- sapply(x, nchar) ns <- nc %/% 2 cbind(a1 = substring(x, 1, ns), a2 = substring(x, ns + 1, nc)) } > shalve(a) a1a2 [1,] "1" "1" [2,] "1" "2" [3,] "12" "34" [4,] "12" "45" [5,] "124" "567" [6,] "126" "786" [7,] "14

Re: [R] Substring a column vector

2011-07-06 Thread Peter Maclean
How to substring the following vector (in data frame b) >b a 11 12 1234 1245 124567 126786 145769 such that: a1    a2 1 1 1 2 12    23 12    34 124   567 126   787 145   769   I tried logical commands with substr() did not work out. __ R-help@r