Selecting from a Dataframe

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

Selecting from a Dataframe

Dan Chan
Hi,

I have a data frame with many fields and there are many records.
One of the fields is county names in Georgia.
I want to select all the records for 3 of the counties.
How can I do that?

DailyCounty is the dataframe that holds the data.  One of the fields is
County.  The following statement will extract all records for Appling
County and store as Appling.  

Appling <- subset(DailyCounty, DailyCounty$County== ("Appling"))

I suppose I can do the same for the other two counties, but how can I
combine them into one single data frame?  Each county has a different
numbers of records in the dataframe DailyCounty.

Thank you.

Daniel Chan
Meteorologist
Georgia Forestry Commission
P O Box 819
Macon, GA
31202
Tel: 478-751-3508
Fax: 478-751-3465

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Selecting from a Dataframe

Bert Gunter
?"%in%"

as in

chosenCounties<-subset(DailyCounty, DailyCounty$County%in%
c("Appling","county2Name","county3Name"))



-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Dan Chan
> Sent: Tuesday, April 04, 2006 10:42 AM
> To: [hidden email]
> Subject: [R] Selecting from a Dataframe
>
> Hi,
>
> I have a data frame with many fields and there are many records.
> One of the fields is county names in Georgia.
> I want to select all the records for 3 of the counties.
> How can I do that?
>
> DailyCounty is the dataframe that holds the data.  One of the
> fields is
> County.  The following statement will extract all records for Appling
> County and store as Appling.  
>
> Appling <- subset(DailyCounty, DailyCounty$County== ("Appling"))
>
> I suppose I can do the same for the other two counties, but how can I
> combine them into one single data frame?  Each county has a different
> numbers of records in the dataframe DailyCounty.
>
> Thank you.
>
> Daniel Chan
> Meteorologist
> Georgia Forestry Commission
> P O Box 819
> Macon, GA
> 31202
> Tel: 478-751-3508
> Fax: 478-751-3465
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Selecting from a Dataframe

Andy Bunn
In reply to this post by Dan Chan
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]]On Behalf Of Dan Chan
> Sent: Tuesday, April 04, 2006 1:42 PM
> To: [hidden email]
> Subject: [R] Selecting from a Dataframe
>
>
> Hi,
>
> I have a data frame with many fields and there are many records.
> One of the fields is county names in Georgia.
> I want to select all the records for 3 of the counties.
> How can I do that?
>
> DailyCounty is the dataframe that holds the data.  One of the fields is
> County.  The following statement will extract all records for Appling
> County and store as Appling.  
>
> Appling <- subset(DailyCounty, DailyCounty$County== ("Appling"))

ThreeCounties <- subset(DailyCounty, County== ("Appling") |
                 County== ("Baldwin") | County== ("Barrow"))


HTH, Andy


>
> I suppose I can do the same for the other two counties, but how can I
> combine them into one single data frame?  Each county has a different
> numbers of records in the dataframe DailyCounty.
>
> Thank you.
>
> Daniel Chan
> Meteorologist
> Georgia Forestry Commission
> P O Box 819
> Macon, GA
> 31202
> Tel: 478-751-3508
> Fax: 478-751-3465
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html