[R] Subset a column with specific characters
David Winsemius
dwinsemius at comcast.net
Fri Sep 5 01:38:09 CEST 2014
On Sep 4, 2014, at 2:58 PM, Kuma Raj wrote:
> This post has NOT been accepted by the mailing list yet.
Well, it has now. Were you earlier posting from Nabble? (Not an efficient strategy.)
> I would like to subset a column based on the contents of a column with
> specific character. In the sample data I wish to do the following:
>
> First keep the data based on column "prog" if prog contains "ca", and
> secondly to drop if race contains "ic"
>
> Thanks
>
> library(foreign)
> hsb2 <- read.dta('http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta')
> NROW( hsb2[ grepl("ca", hsb2$prog) & !grepl("ic", hsb2$race) , ] )
[1] 120
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list