I downloaded a data set and just realized that the columns (newly infected cases of HIV by year) have numbers greater than 9999 expressed with "k." Eg we have 300, 1100, and then 21k. I guess this is why R interpreted the columns as characters.
Sorry, this may make some of you laugh, but - is there a function in R that addresses this?
I can do very primitive programming (not in R though) and I guess the approach would be to replace every instance of "k" with "000," and then convert the columns to numeric.
But is there another way?
Hi! Welcome to the RStudio Community.
If all you're dealing with is converting "k" to "000" in a character vector (or data frame variable) you can do that pretty easily:
x <- c("997", "998", "999", "1k") as.numeric(gsub("k", "000", x))  997 998 999 1000
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.