Learn R Programming

plyr (version 1.5.1)

liply: Experimental iterator based version of llply.

Description

Experimental iterator based version of llply.

Usage

liply(.iterator, .fun, ...)

Arguments

.iterator
iterator object
.fun
function to apply to each piece
...
other arguments passed on to .fun

Details

Because iterators do not have known length, liply starts by allocating an output list of length 50, and then doubles that length whenever it runs out of space. This gives O(n ln n) performance rather than the O(n ^ 2) performance from the naive strategy of growing the list each time.

Examples

Run this code
if(require("iterators")) {
system.time(dlply(baseball, "id", summarise, mean_rbi = mean(rbi)))
system.time({
baseball_id <- isplit2(baseball, baseball$id)
liply(baseball_id, summarise, mean_rbi = mean(rbi, na.rm = TRUE))
})
# Iterators get used up:
liply(baseball_id, summarise, mean_rbi = mean(rbi, na.rm = TRUE))
}

Run the code above in your browser using DataLab