Skip to content
Back to formatted view

Raw Message

Message-ID: <20090527110537.GC1197@anakin.ifi.uio.no>
Date: 2009-05-27T11:05:37Z
From: Zeljko Vrba
Subject: How to exclude a column by name?
In-Reply-To: <4A1D1B79.7060600@geo.uu.nl>

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"]?)