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. ______________________________________________ R-help@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.