Re: [R] replace certain elements in data frame

2011-04-23 Thread sneaffer
Hey, Try the following code: a=c(1,2,3,4,5) b=c(10,20,30,40,50) c=c(100,200,300,400,500) d=c(1000,8210,9000,8310, 7000) e=c(,,9190,,) to.replace=c(8210,8310,9190) df = data.frame(a,b,c,d,e) xdf <- apply(df, 2, function(x) x %in% to.replace) df[xdf] <- "others" -- View this mess

Re: [R] replace certain elements in data frame

2011-04-23 Thread Joshua Wiley
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 wan

[R] replace certain elements in data frame

2011-04-23 Thread Yosub Jung
Hello, I have a data frame with 2 columns: year and code. In code column, I want to replace elements that are not "8210", "8310", or "9190" with "others". -- Sincerely, Yosub Jung. [[alternative HTML version deleted]] __ R-help@r-project.org