[R] Exclude rows by criteria

arun smartpink111 at yahoo.com
Thu Apr 17 11:27:42 CEST 2014


Hi,
May be this helps:
set.seed(49)
dat1 <- data.frame(group=factor(sample(4,20,replace=TRUE)), year=factor(sample(2003:2014,20,replace=TRUE))) 

indx <- with(dat1, as.numeric(as.character(year)) <=2007 | as.numeric(as.character(year)) >2012 )

with(dat1[!indx,],chisq.test(group,year))
A.K.



I am analyzing two columns (both are factors): group and year by chi-square test: chisq.test(group,year) How can I exclude data (rows) where year is <2007 or >2012 ?
Thanks for your help.




More information about the R-help mailing list