Re: [R] replace certain elements in data frame

From: sneaffer <sneaffer_at_mail.ru>
Date: Sat, 23 Apr 2011 18:01:22 -0700 (PDT)

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(5555,6666,9190,7777,3333)

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 message in context: http://r.789695.n4.nabble.com/replace-certain-elements-in-data-frame-tp3470629p3470905.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 24 Apr 2011 - 05:47:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Apr 2011 - 06:10:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive