2

I have this code

 // [[Rcpp::export]]
void testDf(Rcpp::DataFrame pq)
{
  Rcpp::NumericVector p = pq[1];
  std::cout<<p[2]<<std::endl;
}

Which is the right way of accessing an element of virtual row of a particular column . But if I do this

// [[Rcpp::export]]
void testDf(Rcpp::DataFrame pq)
{
  std::cout<<pq[1][2]<<std::endl;
 }    

It return to me an error that operator[] is ambiguous . But if we see, DataFrame is just a set of vectors. From the Data structure point of view DataFrame will hold pointers to set of vectors. So the [] operator will return me a pointer and I can further access the pointer's different element through dereferencing it. Please correct me if I am wrong. Just started with the awesome Rcpp package. I am having few theoretical questions like this. I will be grateful for the answers.

Jaap
  • 81,064
  • 34
  • 182
  • 193
srinath29
  • 345
  • 2
  • 4
  • 14
  • You should get the column first in a classed variable then the row of the column. http://gallery.rcpp.org/articles/modifying-a-data-frame/ has an example (it's setting a value there but the idiom holds for getting). – hrbrmstr Aug 19 '15 at 10:52
  • No... No I know how to edit or subset a data frame. I want to know why that "[]" operator cannot be used successively ... – srinath29 Aug 21 '15 at 08:36

0 Answers0