I need help in converting character values such as "80.5K" or "5.79M" to a numeric data type.
I tried using the gsub
function, but not sure on how to work with the numbers after the decimal point
gsub(pattern = "K", replacement = "" , "80.53K")
I need help in converting character values such as "80.5K" or "5.79M" to a numeric data type.
I tried using the gsub
function, but not sure on how to work with the numbers after the decimal point
gsub(pattern = "K", replacement = "" , "80.53K")
You can use parse_number()
from readr
library.
library(tidyverse)
value1 <- "80.5K"
parse_number(value1)
value2 <- "5.79M"
parse_number(value2)
Gives:
80.5
5.79
Reference - https://readr.tidyverse.org/reference/parse_number.html