+2 votes
in Programming Languages by (9.6k 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 (42.1k 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

Related questions

+4 votes
1 answer
+5 votes
1 answer
+2 votes
1 answer
...