[R] "[.data.frame" and lapply

baptiste auguie ba208 at exeter.ac.uk
Wed Mar 25 19:56:57 CET 2009


Dear all,


Trying to extract a few rows for each element of a list of  
data.frames, I'm puzzled by the following behaviour,


> d <- lapply(1:4,  function(i) data.frame(x=rnorm(5), y=rnorm(5)))
> str(d)
>
> lapply(d, "[", i= c(1)) # fine,  this extracts the first columns
> lapply(d, "[", j= c(1, 3)) # doesn't do nothing ?!
>
> library(plyr)
>
> llply(d, "[", j= c(1, 3)) # same


Am i misinterpreting the meaning of "j", which I thought was an  
argument of the method "[.data.frame"?


> args(`[.data.frame`)
> function (x, i, j, drop = if (missing(i)) TRUE else length(cols) ==
>    1)
>

Many thanks,

baptiste

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag




More information about the R-help mailing list