[R] How to exclude a column by name?
Zeljko Vrba
zvrba at ifi.uio.no
Wed May 27 13:05:37 CEST 2009
On Wed, May 27, 2009 at 12:52:41PM +0200, Paul Hiemstra wrote:
>
> This piece of code does the trick. Most important is the which() command:
>
> df = data.frame(a = runif(10), b = runif(10))
> df[,-which(names(df) == "a")]
>
Thanks to you and Linlin. It did not occur to me to use which(); I thought
that there would be a shorter way to accomplish this since names are
first-class indices for data frames and arrays. (Or are they? What happens
under the hood when I write df[,"a"]?)
More information about the R-help
mailing list