[Rcpp-devel] Efficient DataFrame access by row & column
romain at r-enthusiasts.com
Wed Feb 20 09:56:06 CET 2013
Le 20/02/13 00:09, Yan Zhou a écrit :
> The most inefficient part I see is the creation of a new NumericVector inside the inner most loop. You copied each column n times, of which n-1 times are unnecessary.
No. This does not copy data. This uses time to protect it, etc ... but
the data in the vector is not copied.
> Yan Zhou
> On Feb 19, 2013, at 11:02 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>> On 19 February 2013 at 22:35, Ken Williams wrote:
>> | I have a need to loop through all the entries of a DataFrame by row, then
>> | column. I know two different ways:
>> There have been prior discussions of this topic, as well as example posts --
>> even leading to a Rcpp Gallery article. Did you read any of these? It wasn't
>> clear from your post.
>> | I?m also curious why it?s a syntax error in Case A to just write `df[j][i]` or
>> Eeeek. I prefer the more C++-y way of writing df(j,i). Square brackets only
>> work for vectors, and even then you may be better off with x(i) for
>> Overall, your premise may be wrong too. "We all know" that a data.frame is
>> not the fastest data structure in R, so by forcing ourselves to the same
>> access are we not handycapping ourselves.
>> Once you are in C++, you can use whatever C++ datatype you like. A
>> data.frame really is just a list of vectors, each of the vectors has eg a
>> begin(0 iterator which you can (fairly costlessly) instantiate STL types.
>> And those give you performance guarantees.
>> Hope this helps, Dirk
>> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
>> Rcpp-devel mailing list
>> Rcpp-devel at lists.r-forge.r-project.org
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
Professional R Enthusiast
+33(0) 6 28 91 30 30
R Graph Gallery: http://gallery.r-enthusiasts.com
|- http://bit.ly/14LJhmm : bibtex 0.3-5
`- http://bit.ly/RE6sYH : OOP with Rcpp modules
More information about the Rcpp-devel