Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Another tweak to rbind.fill

  • Loading branch information...
commit 5ba6a1e94d1beee2d6e5fbec48a215dcd1154a07 1 parent 071076b
@hadley authored
Showing with 9 additions and 6 deletions.
  1. +2 −0  NEWS
  2. +7 −6 R/rbind.r
View
2  NEWS
@@ -1,5 +1,7 @@
plyr 0.1.8 (2008-XX-XX) ---------------------------------------------------
+* made rbind a little faster (~20%) using an idea from Richard Raubertas
+
plyr 0.1.7 (2008-04-15) ---------------------------------------------------
Ensure that rbind.fill copies attributes.
View
13 R/rbind.r
@@ -47,21 +47,22 @@ rbind.fill <- function(...) {
# Compute start and end positions for each matrix
pos <- matrix(cumsum(rbind(1, rows - 1)), ncol = 2, byrow = T)
- # Do in reverse so first step expands to largest size
- for(i in rev(seq_along(rows))) {
+ for(i in seq_along(rows)) {
rng <- pos[i, 1]:pos[i, 2]
df <- dfs[[i]]
for(var in names(df)) {
if (length(df[[var]]) > 0) {
- output[[var]][rng] <- df[[var]]
-
if (!var %in% seen) {
- length(output[[var]]) <- nrows
- attributes(output[[var]]) <- attributes(df[[var]])
+ output[[var]] <- rep(df[[var]], length.out = nrows)
+ output[[var]][] <- NA
+
seen <- c(seen, var)
}
+
+ output[[var]][rng] <- df[[var]]
+
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.