[Rcpp-devel] table, rev and missing names
Sven E. Templer
sven.templer at gmail.com
Fri Jun 6 12:58:24 CEST 2014
Hi,
consider this code:
require(Rcpp)
require(inline)
t <- cxxfunction(sig=c(xx="character"), plugin="Rcpp", body='
CharacterVector x(xx);
IntegerVector t = table(x);
return t;')
r <- cxxfunction(sig=c(xx="character"), plugin="Rcpp", body='
CharacterVector x(xx);
IntegerVector t = table(x);
IntegerVector r = rev(t);
return r;')
o <- cxxfunction(sig=c(xx="character"), plugin="Rcpp", body='
CharacterVector x(xx);
IntegerVector t = table(x);
CharacterVector n = t.names();
IntegerVector r = rev(t);
r.names() = rev(n);
return r;')
t(c('a','a','b',NA))
r(c('a','a','b',NA))
o(c('a','a','b',NA))
Reversed vectors loose their name ( t() vs r() ) and have to be copied
and reversed 'manually' ( as in o() ). Is rev() a function declared by
Rcpp, if so can names be reserved while reverting or is there any
other easier solution than in o() ?
Thank you!
Sven
More information about the Rcpp-devel
mailing list