Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Apply

Suppose you have a data frame from which you wish to extract a subset of rows, and you have a matrix to record the start and finish of the sequences of indicies you wish to extract. Whilst a for loop is obvious, mapply works nicely.



> x <- rbind(c(2,5), c(7,9), c(15,20))
> x
     [,1] [,2]
[1,]    2    5
[2,]    7    9
[3,]   15   20
> unlist(mapply(seq, x[,1], x[,2]))
 [1]  2  3  4  5  7  8  9 15 16 17 18 19 20



Copyright © 2004-2010 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010