Вот один вариант использования stringr
:
# Packages used
library(stringr) # for str_extract and str_replace (could be done in base with gsub)
library(magrittr) # for the pipe operator %>%
players$Measure <- str_extract(players$Value, "[A-z]+")
players$Value_clean <-
players$Value %>%
str_extract("[\\d,]+") %>%
str_replace(",", ".") %>%
as.numeric()
players$Value_clean <- players$Value_clean * ifelse(players$Measure == "Th", 1000, 1000000)
players
# Name Value Measure Value_clean
# 1 Mikael Forssell 9,00 Mill. € Mill 9000000
# 2 Hernan Crespo 15,00 Mill. € Mill 15000000
# 3 Nuno Morais 1,00 Mill. € Mill 1000000
# 4 Alex 10,00 Mill. € Mill 10000000
# 5 Filipe Oliveira 450 Th. € Th 450000
# 6 Craig Rocastle 100 Th. € Th 100000
# 7 Wayne Bridge 7,75 Mill. € Mill 7750000
# 8 Jiri Jarosik 6,50 Mill € Mill 6500000
# 9 Joe Keenan 600 Th. € Th 600000
Данные
players <- data.frame(
Name = c(
"Mikael Forssell", "Hernan Crespo", "Nuno Morais", "Alex",
"Filipe Oliveira", "Craig Rocastle", "Wayne Bridge", "Jiri Jarosik",
"Joe Keenan"
),
Value = c(
"9,00 Mill. €", "15,00 Mill. €", "1,00 Mill. €",
"10,00 Mill. €", "450 Th. €", "100 Th. €", "7,75 Mill. €",
"6,50 Mill €", "600 Th. €"
),
stringsAsFactors = FALSE
)