I am trying to suppress all values in my data frame that are less than 5.
data[data < 5] <- NA
For the most part this works fine. However I also have some values that are categorical age groups "0-19" "20-24" and so on. I guess R is doing the subtraction and removing these as well. Is there a way to do this that ignores any value that isn't an integer?
Edit: Some dummy data as an example:
dummydata<-as.data.frame(rbind(c('0-19','4','5'),c('20-24','6','1')))
> dummydata
[,1] [,2] [,3]
[1,] "0-19" "4" "5"
[2,] "20-24" "6" "1"
dummydata[dummydata < 5] <- NA
> dummydata
[,1] [,2] [,3]
[1,] NA NA "5"
[2,] NA "6" NA
Desired output:
[,1] [,2] [,3]
[1,] "0-19" NA "5"
[2,] "20-24" "6" NA
question from:
https://stackoverflow.com/questions/66058399/r-data-suppression-that-ignores-non-integers 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…