[R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread Jeff Johnson
I'm running the following to get what I would expect is a subset of countries that are not equal to US AND COUNTRY is not in one of my validcountries values. non_us - subset(mydf, (COUNTRY %in% validcountries) COUNTRY != US, select = COUNTRY, na.rm=TRUE) however, when I then do table(non_us) I

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread arun
Hi, Try: table(as.character(non_us[,COUNTRY])) A.K. On Tuesday, January 14, 2014 3:17 PM, Jeff Johnson mrjeffto...@gmail.com wrote: I'm running the following to get what I would expect is a subset of countries that are not equal to US AND COUNTRY is not in one of my validcountries values.

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread Marc Schwartz
On Jan 14, 2014, at 1:38 PM, Jeff Johnson mrjeffto...@gmail.com wrote: I'm running the following to get what I would expect is a subset of countries that are not equal to US AND COUNTRY is not in one of my validcountries values. non_us - subset(mydf, (COUNTRY %in% validcountries) COUNTRY

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Johnson Sent: Tuesday, January 14, 2014 11:39 AM To: r-help@r-project.org Subject: [R] Subsetting on multiple criteria (AND condition) in R I'm running the following to get what I

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread Jeff Johnson
Thanks so much Marc and for those that responded. Mark's suggestion with droplevels gave me the desired result. I'm new to figuring out how to post reproducible code. I'll try using the set.seed and rnorm functions next time and hope that does the trick. Thanks everyone! On Tue, Jan 14, 2014