I have a data set with several column, for each column i want to find a threshold value to make the NA count between 1010-1020. Below is the way i tried coding. Here is the example for the data.
X1 X2 X3
1.51 0.00 0.00
0.31 3.90 0.00
0.64 13.64 0.00
0.26 9.66 0.00
0.36 0.04 0.00
0.51 0.03 0.00
0.30 0.08 0.02
0.01 0.20 0.04
0.02 0.03 0.00
0.00 0.47 0.00
0.00 1.44 5.54
0.00 2.68 0.74
0.03 0.68 5.49
1.72 0.08 1.54
threshold=seq(0.5,by=0.1,5)
for (j in threshold){
for (i in 1:3){
data[,i]=ifelse(data[,i]> j,data[,i],NA)
if((sum(is.na(data[,i]))==range(2,4)) {break
}
}}