[Rcpp-devel] Getting names

Søren Højsgaard sorenh at math.aau.dk
Tue Mar 25 11:02:54 CET 2014


Something like this?

x <- c(a=1, b=2)
f <- cppFunction("CharacterVector foo(NumericVector x){return x.names();}")
> f(x)
[1] "a" "b"

Søren


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 David Edwards
Sent: 25. marts 2014 10:45
To: 'rcpp-devel at lists.r-forge.r-project.org'
Subject: [Rcpp-devel] Getting names

Another novice question: the function

// [[Rcpp::export]]
IntegerVector maketable(IntegerVector x) {
  IntegerVector tab=table(x);
  return tab;
}

returns a named vector, and is about twice as fast as the R function 'table'. Is there a way to extract the names of the vector as a CharacterVector (or even better here, as an IntegerVector)?

BR David


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140325/88df4ce0/attachment.html>


More information about the Rcpp-devel mailing list