Re: [R] omitting columns from a data frame

2011-06-21 Thread David Winsemius
On Jun 21, 2011, at 12:22 AM, Joshua Wiley wrote: On Mon, Jun 20, 2011 at 8:55 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Too funny! how about subset? Sure, that is one option. Each of the following will also work. The ones wrapped with c() can easily omit more than one at a time.

Re: [R] omitting columns from a data frame

2011-06-21 Thread Ista Zahn
I would cation people not to use the -which strategy because entering a value that doesn't exist as a column name returns a zero-column data.frame, without so much as a warning. This can be a problem if you don't know if a column exists but just want to make sure it doesn't, or if you make a typo.

Re: [R] omitting columns from a data frame

2011-06-21 Thread David Winsemius
On Jun 21, 2011, at 9:57 AM, Ista Zahn wrote: I would cation people not to use the -which strategy because entering a value that doesn't exist as a column name returns a zero-column data.frame, without so much as a warning. This can be a problem if you don't know if a column exists but just

Re: [R] omitting columns from a data frame

2011-06-21 Thread Joshua Wiley
On Tue, Jun 21, 2011 at 6:57 AM, Ista Zahn iz...@psych.rochester.edu wrote: I would cation people not to use the -which strategy because entering a value that doesn't exist as a column name returns a zero-column data.frame, without so much as a warning. This can be a problem if you don't know

Re: [R] omitting columns from a data frame

2011-06-21 Thread Albert-Jan Roskam
? ~~ From: Joshua Wiley jwiley.ps...@gmail.com To: Ista Zahn iz...@psych.rochester.edu Cc: R-Help r-h...@stat.math.ethz.ch Sent: Tue, June 21, 2011 5:05:27 PM Subject: Re: [R] omitting columns from a data frame On Tue, Jun 21, 2011 at 6:57 AM, Ista Zahn iz

Re: [R] omitting columns from a data frame

2011-06-21 Thread Bill.Venables
Hodgess Sent: Tuesday, 21 June 2011 1:45 PM To: R help Subject: [R] omitting columns from a data frame Dear R People: I have a data frame, xm1, which has 12 rows and 4 columns. If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as it should be. Now, is there a way to use the names

[R] omitting columns from a data frame

2011-06-20 Thread Erin Hodgess
Dear R People: I have a data frame, xm1, which has 12 rows and 4 columns. If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as it should be. Now, is there a way to use the names of the columns to omit them, please? Thanks so much in advance! Sincerely, Erin -- Erin Hodgess

Re: [R] omitting columns from a data frame

2011-06-20 Thread Jorge Ivan Velez
Hi Erin, One option woild be subset(), especially the select parameter. HTH, Jorge On Mon, Jun 20, 2011 at 11:45 PM, Erin Hodgess wrote: Dear R People: I have a data frame, xm1, which has 12 rows and 4 columns. If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as it

Re: [R] omitting columns from a data frame

2011-06-20 Thread Joshua Wiley
Hi Erin, See inline. On Mon, Jun 20, 2011 at 8:45 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I have a data frame, xm1, which has 12 rows and 4 columns. If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as it should be. Okay, so you know how to use the

Re: [R] omitting columns from a data frame

2011-06-20 Thread Ista Zahn
Hi Erin, As you've seen from the responses so far there are many ways to do it. I like to do xm1[setdiff(names(xm1), c(x1, x2, ...))] where xm1 is the data.frame, and x1, x2, ... are the columns you wish to exclude. Just another option. Best, Ista On Mon, Jun 20, 2011 at 11:52 PM, Joshua Wiley

Re: [R] omitting columns from a data frame

2011-06-20 Thread Joshua Wiley
On Mon, Jun 20, 2011 at 8:55 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Too funny! how about subset? Sure, that is one option. Each of the following will also work. The ones wrapped with c() can easily omit more than one at a time. mtcars[, -which(names(mtcars) == drat)] mtcars[,