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

From: Thomas Levine <thomas.levine_at_gmail.com>
Date: Sun, 24 Apr 2011 12:56:08 -0400

As Joshua said, mine was indeed different from yours. And it didn't work on non-numeric data. But this one seems to work right:

random.del_vec <- function (x, n.keeprows, del.percent){   del<-function(notkeep){
    k<-floor(length(notkeep)*del.percent/100)     notkeep[sample.int(length(notkeep),k)]<-NA     notkeep
  }
  change<-(n.keeprows+1):nrow(x)
   x[change,]<-t(apply(x[change,],1,del))   x
}

On the other hand, maybe you really didn't want the stratification by row.

Tom

On Sun, Apr 24, 2011 at 8:31 AM, sneaffer <sneaffer_at_mail.ru> wrote:
> 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.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.
>



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 - 17:25:33 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 - 19:30: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