Is there a simple way to convert data in a dataframe from fraction to decimal format? I have a column of data that that's been recorded as a fraction:
Levels: 1/2 1/3 1/4 1/5 1/8 2/3
Is there a quick way to convert it to .5 .333 25 .2 .125 .67?
Here's a way I've done that in the past.
> frac <- c("1/2","1/3","1/4","1/5","1/8","2/3")
> sapply(frac, function(x) eval(parse(text=x)))
1/2 1/3 1/4 1/5 1/8 2/3
0.5000000 0.3333333 0.2500000 0.2000000 0.1250000 0.6666667
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With