How to convert character of percentage into numeric in R

10% is per definition not a numeric vector. Therefore, the answer NA is correct. You can convert a character vector containing these numbers to numeric in this fashion:

percent_vec = paste(1:100, "%", sep = "")
as.numeric(sub("%", "", percent_vec))

This works by using sub to replace the % character by nothing.

Leave a Comment