constructing a Data Frame in Rcpp

前端 未结 4 1731
名媛妹妹
名媛妹妹 2020-12-14 23:20

I want to construct a data frame in an Rcpp function, but when I get it, it doesn\'t really look like a data frame. I\'ve tried pushing vectors etc. but it leads to the same

4条回答
  •  温柔的废话
    2020-12-15 00:15

    Briefly:

    • DataFrames are indeed just like lists with the added restriction of having to have a common length, so they are best constructed column by column.

    • The best way is often to look for our unit tests. Her inst/unitTests/runit.DataFrame.R regroups tests for the DataFrame class.

    • You also found the .push_back() member function in Rcpp which we added for convenience and analogy with the STL. We do warn that it is not recommended: due to differences with the way R objects are constructed, we essentially always need to do full copies .push_back is not very efficient.

    • Despite me answering here frequently, the rcpp-devel list a better place for Rcpp questions.

提交回复
热议问题