Message-ID: <47E98B38.8060307@biostat.wisc.edu>
Date: 2008-03-25T23:31:04Z
From: Erik Iverson
Subject: Combining logical operators to extract columns from a dataframe
In-Reply-To: <e40d78ce0803251557y49a3630bk6d9fd7c19f18fd83@mail.gmail.com>
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.