Skip to content
Prev 4928 / 10988 Next

[Rcpp-devel] Joining each row of CharacterMatrix to return a CharacterVector?

Hi,
On Mon, Dec 10, 2012 at 5:43 PM, <hickey at wehi.edu.au> wrote:
You can do it more (speed) efficiently in R, too, if memory is no
object, since you can just R-loop over the far fewer columns:

R> X <- matrix(c("Z", "z", "A", "A"), nrow=2)
R> Y <- do.call(paste0, lapply(1:ncol(X), function(i) X[,i]))
R> Y
[1] "ZA" "zA"

but doing it in C(++) will definitely be more memory efficient, and
likely speed efficient, too, so it will be a good exercise, and for
that Dirk has given you a good head start :-)

HTH,
-steve