Skip to content
Browse files

Improve speed of colwise

  • Loading branch information...
1 parent 489edc0 commit b9bc3d5acda7c3850dbd709a3003ed7d9fa7cbbf @hadley committed Apr 11, 2009
Showing with 3 additions and 1 deletion.
  1. +1 −0 NEWS
  2. +2 −1 R/helper-col-wise.r
View
1 NEWS
@@ -12,6 +12,7 @@ Speed-ups
* massive speed ups for splitting large arrays
* fixed typo that was causing a 50% speed penalty for d*ply
* rewritten rbind.fill is considerably (> 4x) faster for many data frames
+* colwise about twice as fast
Bug fixes:
View
3 R/helper-col-wise.r
@@ -46,10 +46,11 @@ colwise <- function(.fun, .cols = function(x) TRUE) {
}
function(df, ...) {
+ stopifnot(is.data.frame(df))
filtered <- filter(df)
if (ncol(filtered) == 0) return(data.frame())
- df <- do.call("data.frame", alply(filtered, 2, .fun, ...))
+ df <- as.data.frame(llply(filtered, .fun, ...))
names(df) <- names(filtered)
df
}

0 comments on commit b9bc3d5

Please sign in to comment.
Something went wrong with that request. Please try again.