Skip to content
Prev 257839 / 398502 Next

replace certain elements in data frame

Hi Yosub,

if "dat" is your data frame, try something like (untested):

dat$code[!dat$code %in% c("8210", "8310", "9190")] <- "others"

the general idea being create a logical vector of codes that match the
three you want, use "!" to negate this (so you are getting all codes
NOT in the ones you want), and then use this to selectively assign
"others".

For documentation, see

?match
?Logic

Hope this helps,

Josh
On Sat, Apr 23, 2011 at 11:31 AM, Yosub Jung <yosubjung at berkeley.edu> wrote: