PR#6614

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

PR#6614

David Hugh-Jones-3
I agree with the submitter that this needs some kind of solution.
Although data.frame[,-12] works, how do I drop a named column (the
most common use case)? (I found this bug while searching for an
answer.)

cheers
David

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: PR#6614

Gabor Grothendieck
Try this:

 subset(iris, select = - Species)


On 2/22/06, [hidden email] <[hidden email]> wrote:

> I agree with the submitter that this needs some kind of solution.
> Although data.frame[,-12] works, how do I drop a named column (the
> most common use case)? (I found this bug while searching for an
> answer.)
>
> cheers
> David
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: PR#6614

Peter Dalgaard
"Gabor Grothendieck" <[hidden email]> writes:

> Try this:
>
>  subset(iris, select = - Species)

Or, canonically,

nm <- names(iris)
iris[, nm != "Species" ]

iris[, -match("Species", nm)]
 

>
> On 2/22/06, [hidden email] <[hidden email]> wrote:
> > I agree with the submitter that this needs some kind of solution.
> > Although data.frame[,-12] works, how do I drop a named column (the
> > most common use case)? (I found this bug while searching for an
> > answer.)
> >
> > cheers
> > David
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: PR#6614

Bill Dunlap
On Wed, 23 Feb 2006, Peter Dalgaard wrote:

> "Gabor Grothendieck" <[hidden email]> writes:
>
> > Try this:
> >
> >  subset(iris, select = - Species)
>
> Or, canonically,
>
> nm <- names(iris)
> iris[, nm != "Species" ]
>
> iris[, -match("Species", nm)]
>
> >
> > On 2/22/06, [hidden email] <[hidden email]> wrote:
> > > I agree with the submitter that this needs some kind of solution.
> > > Although data.frame[,-12] works, how do I drop a named column (the
> > > most common use case)? (I found this bug while searching for an
> > > answer.)

That code with match only works if "Species" is actually
a column of iris.  If not, your result depends on whether
you have a data.frame (an error) or a matrix (a column
of NA's).

I found some mail in a 15 year old sent-mail file that suggested
allowing the tag 'except=' on any of the arguments to "[" to
replace/extend the limited negative integer convention.  The idea was
that
    iris[ except=c(10:20), except=c("Petal.Width","Petal.Length")) ]
would return all rows except 10:20 and all columns except
the ones named.
    iris[ except=integer(0), ]
would return all rows of iris, while iris[-integer(0), ] returns
no rows of iris.

This abuses the tag= notation, but the "[" function doesn't
really support the i= and j= tags that some people expect.

This would take care of the problem that subset(data.frame,select=-name)
only lets you omit columns.

The mail had a version of [.data.frame (for Splus 2.1?) that
implemented this, although, if it is to be used it should be
implemented in the most primitive [ code so all methods use it.

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: PR#6614

David Hugh-Jones-3
One thing I notice is that after using subset() on a data frame
imported from SPSS, my variable.names attribute disappeared. I guess
what I would expect is for a subset() method always to preserve
everything but the omitted column.

Cheers
David

On 27/02/06, Bill Dunlap <[hidden email]> wrote:

> On Wed, 23 Feb 2006, Peter Dalgaard wrote:
>
> > "Gabor Grothendieck" <[hidden email]> writes:
> >
> > > Try this:
> > >
> > >  subset(iris, select = - Species)
> >
> > Or, canonically,
> >
> > nm <- names(iris)
> > iris[, nm != "Species" ]
> >
> > iris[, -match("Species", nm)]
> >
> > >
> > > On 2/22/06, [hidden email] <[hidden email]> wrote:
> > > > I agree with the submitter that this needs some kind of solution.
> > > > Although data.frame[,-12] works, how do I drop a named column (the
> > > > most common use case)? (I found this bug while searching for an
> > > > answer.)
>
> That code with match only works if "Species" is actually
> a column of iris.  If not, your result depends on whether
> you have a data.frame (an error) or a matrix (a column
> of NA's).
>
> I found some mail in a 15 year old sent-mail file that suggested
> allowing the tag 'except=' on any of the arguments to "[" to
> replace/extend the limited negative integer convention.  The idea was
> that
>     iris[ except=c(10:20), except=c("Petal.Width","Petal.Length")) ]
> would return all rows except 10:20 and all columns except
> the ones named.
>     iris[ except=integer(0), ]
> would return all rows of iris, while iris[-integer(0), ] returns
> no rows of iris.
>
> This abuses the tag= notation, but the "[" function doesn't
> really support the i= and j= tags that some people expect.
>
> This would take care of the problem that subset(data.frame,select=-name)
> only lets you omit columns.
>
> The mail had a version of [.data.frame (for Splus 2.1?) that
> implemented this, although, if it is to be used it should be
> implemented in the most primitive [ code so all methods use it.
>
> ----------------------------------------------------------------------------
> Bill Dunlap
> Insightful Corporation
> bill at insightful dot com
> 360-428-8146
>
>  "All statements in this message represent the opinions of the author and do
>  not necessarily reflect Insightful Corporation policy or position."
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: PR#6614

Peter Dalgaard
In reply to this post by Bill Dunlap
Bill Dunlap <[hidden email]> writes:

> On Wed, 23 Feb 2006, Peter Dalgaard wrote:
>
> > "Gabor Grothendieck" <[hidden email]> writes:
> >
> > > Try this:
> > >
> > >  subset(iris, select = - Species)
> >
> > Or, canonically,
> >
> > nm <- names(iris)
> > iris[, nm != "Species" ]
> >
> > iris[, -match("Species", nm)]
> >
> > >
> > > On 2/22/06, [hidden email] <[hidden email]> wrote:
> > > > I agree with the submitter that this needs some kind of solution.
> > > > Although data.frame[,-12] works, how do I drop a named column (the
> > > > most common use case)? (I found this bug while searching for an
> > > > answer.)
>
> That code with match only works if "Species" is actually
> a column of iris.  If not, your result depends on whether
> you have a data.frame (an error) or a matrix (a column
> of NA's).
>
> I found some mail in a 15 year old sent-mail file that suggested
> allowing the tag 'except=' on any of the arguments to "[" to
> replace/extend the limited negative integer convention.  The idea was
> that
>     iris[ except=c(10:20), except=c("Petal.Width","Petal.Length")) ]
> would return all rows except 10:20 and all columns except
> the ones named.
>     iris[ except=integer(0), ]
> would return all rows of iris, while iris[-integer(0), ] returns
> no rows of iris.
>
> This abuses the tag= notation, but the "[" function doesn't
> really support the i= and j= tags that some people expect.
>
> This would take care of the problem that subset(data.frame,select=-name)
> only lets you omit columns.
>
> The mail had a version of [.data.frame (for Splus 2.1?) that
> implemented this, although, if it is to be used it should be
> implemented in the most primitive [ code so all methods use it.

>From the language viewpoint, I think that using the same tag multiple
times and mixing up tagged and positional argument matching would be
quite nasty. I actually suspect that the argument matching rules will
make it impossible in R (except possibly from C and .Primitive).

However, it could be possible to have an omit() function, as in

iris[ omit(c(10:20)), omit(c("Petal.Width","Petal.Length")) ]  

all this needs to do is to tack an attribute onto the index which the
indexing code can look for.

--
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel