[R] filtering data frame based on two columns

jim holtman jholtman at gmail.com
Fri Jan 11 13:32:18 CET 2008


Use a single "&"

subdf = df[(df$a==1) & (df$b ==2),]

On Jan 11, 2008 7:26 AM, sun <flyhyena at yahoo.com.cn> wrote:
>
> "sun" <flyhyena at yahoo.com.cn> wrote in message
> news:fm7mtb$tqk$1 at ger.gmane.org...
> > Hi,
> >
> > I have a data frame df with column names a,b and c.
> sorry for some typos.
>
> should be subdf = df[df$a==1,]
> and
> subdf = df[df$a==1 && df$b ==2,]
>
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?




More information about the R-help mailing list