0

im new to R and working on data cleaning and i have a column of Values of football players in my dataframe df with the following notations
df$Value <- c("€110.5M", "€1M", "€200k", "€ 0", "€52M")
I would like to convert this column into either just integers or if a currency type exists into that. I later want to compare them in a plot. I have tried to solve it with something like this:

library(stringr)
df$Value<- str_remove_all(df$Value, "[€]")
df$Value<- str_replace_all(df$Value, "[K]", "000")
df$Value<- strtoi(df$Value)

But this doesn't seem to be a smart way and i dont know how to deal with the decimal places like "€1.5M"

  • This probably already answers the question: https://stackoverflow.com/questions/11340444/convert-numbers-to-si-prefix. Just strip off the currency symbol first. – MrFlick Nov 28 '21 at 19:31
  • I have already seen this article but this only shows the converting the other way doesnt it? I want to get rid of the Ms and Ks and into an integer – lucasgoddamn Nov 28 '21 at 20:40
  • Ah. sorry. Here's the other direction: https://stackoverflow.com/questions/56159114/converting-unit-abbreviations-to-numbers – MrFlick Nov 28 '21 at 20:45

0 Answers0