[R] Introduction of NA:s
John Fox
jfox at mcmaster.ca
Wed Oct 2 14:02:06 CEST 2002
Dear Patrik,
At 12:01 PM 10/2/2002 +0200, Patrik Waldmann wrote:
>Hello,
>
>I wonder if someone could help me with the following: I have generated 10
>000 values from rnorm and now I want to randomly replace 500 of those with
>NA. The problem is that values indexed between 6-10,16-20,26-30.... only
>should be considered for replacement. Any suggestions?
There's probably a cleverer way of doing it, but the following should work:
nums <- 1:10000
data <- rnorm(10000)
data[sample(nums[is.element(nums - 10*floor(nums/10), c(0,6:9))],
500)] <- NA
I hope that this helps,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list