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

+1 vote
by (349k points)
selected by
 
Best answer

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

...