[R] Exclude rows by criteria
smartpink111 at yahoo.com
Thu Apr 17 20:08:40 CEST 2014
If the column is "numeric" class, you don't need as.numeric(as.character(...)). My response was based on your original post
I am analyzing two columns (both are factors):"
Using the same example,
indx1 <- with(dat1,year <=2007 |year >2012)
1: In Ops.factor(year, 2007) : <= not meaningful for factors
2: In Ops.factor(year, 2012) : > not meaningful for factors
> indx1  NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
If you didn't get this messages, probably the column is already "numeric" class.
To avoid confusions (in the future), it is better to post a reproducible example using ?dput()
Thanks for your prompt response. The 'year' variable is already numeric. Do we need to use 'as.numeric(as.character(year)) <=2007' ? Can we not just use 'year<=2007' ?
On Thursday, April 17, 2014 5:27 AM, arun <smartpink111 at yahoo.com> wrote:
May be this helps:
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 )
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