Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R- converting data from fraction to decimal [duplicate]

Tags:

r

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?

like image 908
Nan Avatar asked Aug 13 '10 19:08

Nan


1 Answers

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 
like image 157
Joshua Ulrich Avatar answered Sep 30 '22 05:09

Joshua Ulrich