Hello!
Â
I would like to sample 30 % of cases (with at least 1 value lower than 3 - in
the row) and among them I want to set all values lower than 3 (within selected
cases) as NA (NMAR- Not missing at random). I managed to sample cases, but I
donât know how to set values (lower than 3) as NA.
Â
R code:
Â
x <-
matrix(c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,3,3,3,4),
nrow = 7, ncol=7, byrow=TRUE) ####matrix
Â
pMiss <- 30Â Â Â Â ####percent of missing values
Â
N <- dim(x)[1]Â Â ####number of cases
Â
candidate<-which(x[,1]<3 | x[,2]<3 | x[,3]<3 | x[,4]<3 | x[,5]<3 | x[,6]<3 |
x[,7]<3)Â Â Â #### I want to sample all cases with at least 1 value lower than
3,
so I have to find candidates
Â
idMiss <- sample(candidate, N * p / 100)Â Â Â #### I sampled cases
Â
Now I'd like to set all values among sampled cases as NA.
Â
Any suggestion?
Â
Thanks,
Blaž
[[alternative HTML version deleted]]
______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.