Question

I have a data.frame with 2.5 million obs. of 32 variables, all factors. One variable consists numbers between 0 and 999. I want to convert all the numbers above 99 to NA because the model only accepts numbers with 2 digits.

Thanks,

Tim

Was it helpful?

Solution

######making example data set######
ex=matrix(as.factor(rnorm(6,100,10)),3,2)

ex

#           [,1]      [,2]
# [1,] 113.29893 101.54136
# [2,]  91.55164 101.45872
# [3,] 101.14473  88.19593

ex2=data.frame(ex)
###### solution ######    
ex3=apply(ex2,2,as.numeric)

ex3[ex3>99]=NA

ex3
#         X1       X2
# 1       NA       NA
# 2 91.55164       NA
# 3       NA 88.19593
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top