+2 votes
in Programming Languages by (5.0k points)
I want to convert a vector of numerical strings to a vector of fractions. What function should I use?

E.g.

c("0.34", "0.12", "0.45")

to

c(0.34, 0.12, 0.45)

1 Answer

0 votes
by (32.8k points)

You can use as.numeric() method. It will return the numerical value of the string.

E.g.

> a <- c("0.34", "0.12", "0.45")
> b <- as.numeric(a)
> b
[1] 0.34 0.12 0.45

...