Re: [R] Combining logical operators to extract columns from a dataframe

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Tue, 25 Mar 2008 18:31:04 -0500

mtb954_at_gmail.com wrote:
> Hi R-helpers,
>
> I have a dataframe (called data) with 100 columns, the columns of which are
> named with integers ranging from 1900 to 1999.
>
> I wish to extract those columns which names are >=1950 and <=1970.
>
> I tried:
>
> data2<-subset(data,select=(names(data)>=1950 & names(data)<=1970))
>
> but that doesn't work.
>
> Any ideas?

## untested

data[as.character(1950:1970)]

>
> Thanks! Mark
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 26 Mar 2008 - 02:43:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 26 Mar 2008 - 03:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive