I have a character
variable with ratios (proportions) expressed as strings:
x <- c(\"2/3\", \"5/6\", \"3/11\")
.
I want to conver
tidyerse
If you stumbled onto this post in search of a tidyverse answer here is a simple extension. Note this does use the aforementioned "frowned upon" eval( parse())
library(dplyr)
library(purrr)
# add into a tibble
df <- tibble(fractions = c("2/3", "5/6", "3/11"))
df %>%
mutate(numbers = map_dbl(fractions, ~eval(parse(text = .x))))
#> # A tibble: 3 x 2
#> fractions numbers
#>
#> 1 2/3 0.667
#> 2 5/6 0.833
#> 3 3/11 0.273