[Rcpp-devel] cbind column(s) or rbind row(s) to a NumericMatrix

Søren Højsgaard sorenh at math.aau.dk
Thu Feb 6 18:24:50 CET 2014


I don't think there is a cbind-equivalent in Rcpp, but you can do

cbind1 <- cppFunction("NumericMatrix cbind1 (NumericVector x, NumericVector y){
  NumericMatrix out (x.size(), 2);
  out(_,0) = x; out(_,1)=y;
  return out;
}")

cbind1(1:5, 2:6)

     [,1] [,2]
[1,]    1    2
[2,]    2    3
[3,]    3    4
[4,]    4    5
[5,]    5    6

regards
Søren

-----Original Message-----
From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org] On Behalf Of Hideyoshi Maeda
Sent: 6. februar 2014 18:13
To: rcpp-devel at lists.r-forge.r-project.org
Subject: [Rcpp-devel] cbind column(s) or rbind row(s) to a NumericMatrix

Is there a way to cbind column(s) or rbind row(s) to a NumericMatrix in Rcpp?

I have made a NumericVector that is the same length as the number of rows of a NumericMatrix, and was wondering how to (c)bind them together.

Thanks

HLM
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


More information about the Rcpp-devel mailing list