Аналогично ответу @ akrun, но с str_extract
:
library(dplyr)
df %>%
mutate_all(~ as.numeric(str_extract(., "^\\d+")))
или просто следующим, если вывод не обязательно должен быть числовым:
df %>%
mutate_all(str_extract, "^\\d+")
Результат:
x1 x2 x3 x4
1 56 45 34 76
2 56 56 42 43
3 38 53 56 55
Данные:
df <- structure(list(x1 = structure(c(2L, 3L, 1L), .Label = c("38",
"56", "56+3"), class = "factor"), x2 = c(45L, 56L, 53L), x3 = structure(1:3, .Label = c("34",
"42", "56-1"), class = "factor"), x4 = structure(c(3L, 1L, 2L
), .Label = c("43", "55+3", "76"), class = "factor")), .Names = c("x1",
"x2", "x3", "x4"), class = "data.frame", row.names = c(NA, -3L
))