Displaying 2 results from an estimated 2 matches for "byallrows".
2011 Oct 22
0
simplified multicore by() function
....)) }
## we cbind, so we always get an array back
si <- split(1:nrow(data), INDICES)
soln <- mclapply( si, FUN.i, ... )
rv <- do.call("rbind", add.by.names(soln))
if (ncol(rv)==1) {
nm <- rownames(rv)
rv <- as.vector(rv)
names(rv) <- nm
}
rv
}
mc.byallrows <- function(data, INDICES, FUN, ...) {
FUN.i <- function(.index, ...) { cbind(FUN(data[.index,], ...)) }
si <- as.list(1:nrow(data)) ## a little faster than the split for
large data sets
soln <- mclapply( si, FUN.i, ... )
rv <- do.call("rbind", soln) ## omits nami...
2011 Nov 11
0
mc.cores and computer settings on osx and linux
...) }
if (ncol(rv)==1) {
nm <- rownames(rv)
rv <- as.vector(rv)
names(rv) <- nm
}
rv
}
mc.by <- function(data, INDICES, FUN, ...) { .mc.by(mclapply, data,
INDICES, FUN, ...) }
oc.by <- function(data, INDICES, FUN, ...) { .mc.by(lapply, data,
INDICES, FUN, ...) }
mc.byallrows <- function(data, FUN, ...) {
si <- as.list(1:nrow(data)) ## a little faster than the split for
large data sets
FUN.ON.ROWS <- function(.index, ...) { rv <- FUN(data[.index,],
...); if (is.null(rv)) rv else if (is.vector(rv)) matrix(rv, nrow=1)
else rv }
soln <- mclapply( si,...