s-news
[Top] [All Lists]

[S] Summary: Remove column(s) from data frame?

To: <s-news@wubios.wustl.edu>
Subject: [S] Summary: Remove column(s) from data frame?
From: "David Parkhurst" <parkhurs@indiana.edu>
Date: Thu, 24 Jun 1999 08:42:44 -0500
Sender: owner-s-news@wubios.wustl.edu
Thanks to the many! people who answered my query about removing columns
from a data frame.  (I couldn't track that down in the splus help
system, nor using the indices of a couple of books.)

I'll provide just a few responses, as they cover the gamut:

Bill Venables:
You can do it the same way that you remove columns from a matrix:
Suppose you want to remove columns 2, 3 & 4:

Dat <- Dat[, -(2:4)]  # comma and parens necessary...

You can also remove individual columns by name the same way as you would
remove components from a list

Dat$c2 <- Dat$c3 <- Dat$c4 <- NULL.

Cheryl Howard (using the gui): 
Select the column; Under the Data menu item, select Remove submenu, then
select column.  A dialog will appear to verify which column to remove.

Even easier, but perhaps less obvious, in the second line of the tool
bar (when you have a data frame open) you'll see an icon that in three
light grey bars with a black bar with a down arrow.  This removes the
selected column.

Nick Ellis:
By name? 
dat <- dat[,-match("b",names(dat))]
to remove column with name "b".
Multiple columns?
dat <- dat[,-c(3,6)] 
dat <- dat[,-match(c("b","g"),names(dat))]

Again, thanks to everyone else too.

Dave Parkhurst


-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>