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: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] Im Auftrag von 
> Caroline TRUNTZER
> Gesendet: Dienstag, 01. M�rz 2005 15:04
> An: [email protected]
> 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
> 
> ______________________________________________
> [email protected] mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read 
> the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to