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

From: sneaffer <sneaffer_at_mail.ru>
Date: Sat, 23 Apr 2011 17:37:51 -0700 (PDT)

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*(del.percent/100)
  x.del <- x
  for (i in (n.keeprows+1):nrow(x)){
    j <- sample(1:n.items, k)
    x.del[i,j] <- NA
  return (x.del)

The problems is that random.del turns out to be slow on huge samples. Is there any other more effective/charming way to do the same?


View this message in context: http://r.789695.n4.nabble.com/How-to-erase-replace-certain-elements-in-the-data-frame-tp3470883p3470883.html
Sent from the R help mailing list archive at Nabble.com.

R-help_at_r-project.org mailing list
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:43:51 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 - 09:20:33 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