[Rcpp-devel] Getting names

David Edwards David.Edwards at agrsci.dk
Tue Mar 25 11:29:32 CET 2014

Super, thanks for this

From: Søren Højsgaard [mailto:sorenh at math.aau.dk]
Sent: 25. marts 2014 11:03
To: David Edwards; 'rcpp-devel at lists.r-forge.r-project.org'
Subject: RE: Getting names

Something like this?

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


From: rcpp-devel-bounces at lists.r-forge.r-project.org<mailto: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/d741f7dd/attachment.html>

More information about the Rcpp-devel mailing list