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

From: baptiste auguie <ba208_at_exeter.ac.uk>
Date: Wed, 25 Mar 2009 18:56:57 +0000


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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 25 Mar 2009 - 18:00:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 26 Mar 2009 - 07:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive