[mailto:r-help-boun...@r-project.org] On
Behalf Of Erin 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, whic
ealth, what have
the
Romans ever done for us?
~~
From: Joshua Wiley
To: Ista Zahn
Cc: R-Help
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 wrote:
> I would cat
On Tue, Jun 21, 2011 at 6: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
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 wan
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.
On Jun 21, 2011, at 12:22 AM, Joshua Wiley wrote:
On Mon, Jun 20, 2011 at 8:55 PM, Erin Hodgess
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(m
On Mon, Jun 20, 2011 at 8:55 PM, Erin Hodgess 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[, names(mtcars) != "drat"]
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
Hi Erin,
See inline.
On Mon, Jun 20, 2011 at 8: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 should be.
Okay, so you know how to use the column number to om
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
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
A
11 matches
Mail list logo