Skip to content
Prev 21642 / 63424 Next

Any interest in "merge" and "by" implementations specifically for so

Done interactively, sorting and indexing seemed fast. Here are some timings:
+            xs <- x[idx]
+            is <- i[idx]
+            res <- array(NA, 1e6)
+            idx <- which(diff(is) > 0)
+            startidx <- c(1, idx+1)
+            endidx <- c(idx, length(xs))
+          })
[1] 1.06 0.00 1.09   NA   NA
No, as far as I know, it works on all operating systems. Also, it gets a
little faster if you directly put the sum in the function:
+   for (j in 1:length(res)) {
+     res[j] <- sum(x[startidx[j]:endidx[j]])
+   }
+   res
+ }
[1] 2.67 0.03 2.95   NA   NA

- Tom