I have a character vector that looks like:
"Internet" "Internet" "-1" "-5" "Internet" "Internet"
I want to replace all values that would be negative numeric values (-1, -5, etc)
with NA
.
I did that with this code:
hintsData$WhereSeekHealthInfo[hintsData$WhereSeekHealthInfo < 0] <- NA
That seemed to work:
head(hintsData$WhereSeekHealthInfo)
# [1] "Internet" "Internet" NA NA "Internet" "Internet"
But then when I did
> sum(hintsData$WhereSeekHealthInfo == "Internet")
# [1] NA
Basically I couldn't sum the values anymore because I changed the vector in some way?
Prior to running the NA code I was able to run the code and get this:
> sum(hintsData$WhereSeekHealthInfo == "Internet")
# [1] 1691
So, how can I replace the "-1", "-5" etc values with NA, but still get:
> sum(hintsData$WhereSeekHealthInfo == "Internet")
# [1] 1691
Please let me know if you have an idea. I did find other questions about replacing with NA but as I don't know why I can't count values anymore once I replace with NA I'm not sure what to search on or rule out.