[Rcpp-devel] Performance question about DataFrame
Hadley Wickham
h.wickham at gmail.com
Thu Jan 31 14:45:56 CET 2013
On Fri, Jan 18, 2013 at 6:25 PM, John Merrill <john.merrill at gmail.com> wrote:
> Sure. I'll write something up for the gallery, but here's the crude
> outline.
>
> Here's the C++ code:
Is C++ really necessary here? I have the following R function in plyr:
quickdf <- function(list) {
rows <- unique(unlist(lapply(list, NROW)))
stopifnot(length(rows) == 1)
names(list) <- make_names(list, "X")
class(list) <- "data.frame"
attr(list, "row.names") <- c(NA_integer_, -rows)
list
}
which is basically equivalent (although I do some tricks with
rownames). It's even more efficient if you copy and paste the
contents instead of calling the function because then that avoids
duplicating the input list, and instead modifies it in place.
Hadley
--
Chief Scientist, RStudio
http://had.co.nz/
More information about the Rcpp-devel
mailing list