Re: [R] How to erase (replace) certain elements in the data.frame?

2011-04-24 Thread sneaffer
Thanks a lot, guys. Thomas, your method is great, precisely the thing I've been looking forward to. Oh dear, how I love R for those list comprehension tricks! -- View this message in context: http://r.789695.n4.nabble.com/How-to-erase-replace-certain-elements-in-the-data-frame-tp3470883p3471380.h

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

[R] How to erase (replace) certain elements in the data.frame?

2011-04-23 Thread sneaffer
Hello R-world, Please, help me to get round my little mess I have a data.frame in which I'd rather like some values to be NA for the future imputation process. I've come up with the following piece of code: random.del <- function (x, n.keeprows, del.percent){ n.items <- ncol(x) k <- n.items*(