Jim/Rui:
Strictly speaking, this is wrong. What you have described is MCAR --
missing completely at random -- not MAR. They are different! Nevertheless,
the OP seems to be similarly confused about this, so MCAR may in fact be
what what was wanted. Without further context, it is as clear as mud to
Hi Adam,
Looks like you have a matrix or data frame and want to change one or
more observations to NA. I think this will do the trick:
# assume the matrix or data frame is named "ajdat"
randomNA<-function(x,nNA=1) {
dimx<-dim(x)
x[sample(1:dimx[1],nNA),sample(1:dimx[2],nNA)]<-NA
return(x)
}
So
Hello,
What type of data do you have? A vector? Or is it a matrix, a
data.frame, a list, etc?
Suppose it is a vector named x. Then you could do something like
rate <- 0.2
is.na(x) <- sample(length(x), rate*length(x))
At an R prompt type
?is.na
?sample
Hope this helps,
Rui Barradas
Às 21:
3 matches
Mail list logo