Re: [R] Help : delete at random

From: TEMPL Matthias <Matthias.Templ_at_statistik.gv.at>
Date: Wed 02 Mar 2005 - 01:52:41 EST


Hello,

d <- data.frame(a=c(2,3,4), b=c(2,4,1), c=c(3,5,6))

## one NA

s.r <- sample(dim(d)[1], 1)
s.c <- sample(dim(d)[2], 1)

d.na <- d
d.na[s.r, s.c] <- NA
d.na

# Here a matrix is more comfortable by using sample.

For multiple NA, you should write a loop, but to choose e.g. exact 4 values, it might be, that one value is more than one times chosen. For this purpose you can search at your NA by using which(is.na(d), arr.ind=TRUE) and count only if those index is not a NA at a while loop. This is not an elegant way, but probably it helps you a little bit.

Best,
Matthias

> -----Ursprüngliche Nachricht-----
> Von: r-help-bounces@stat.math.ethz.ch

> [mailto:r-help-bounces@stat.math.ethz.ch] Im Auftrag von

> Caroline TRUNTZER
> Gesendet: Dienstag, 01. März 2005 15:04
> An: R-help@stat.math.ethz.ch
> Betreff: [R] Help : delete at random
>
>
> Hello
> I would like to delete some values at random in a data frame.
> Does anyone know how I could do? With best regards Caroline
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read
> the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 02 02:53:12 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:38 EST