Re: [R] How to filter a data frame?

From: milton ruser <milton.ruser_at_gmail.com>
Date: Tue, 22 Jul 2008 11:11:12 -0300

May be this help you; Just intall.packages("sqldf", dependencies=T)

require(sqldf)
my_df<-data.frame(cbind(gender=sample(c("male","female"),50,replace=T), age=round(rnorm(50, mean=30, sd=5),0)))

my_df_subset_male<-sqldf("select * from my_df where gender=='male'") my_df_subset_male

my_df_subset_male_greater35<-sqldf("select * from my_df where gender=='male' and age>35")
my_df_subset_male_greater35

Good luck

miltinho astronauta

brazil

On 7/22/08, rlearner309 <unixunix99_at_gmail.com> wrote:
>
>
> I have a question about how to filter the data frame:
> Suppose my data frame has variables like gender, age,... How to get a
> subset
> of the data frame, with only female (or male) and/or age > 50...? What is
> the typical syntax? I tried several condition expressions, but none of
> them
> worked...
>
> Thanks a lot!
> --
> View this message in context:
> http://www.nabble.com/How-to-filter-a-data-frame--tp18587502p18587502.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>

        [[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. Received on Tue 22 Jul 2008 - 14:43:17 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 Tue 22 Jul 2008 - 15:01:57 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