- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert a decimal value or a vector of decimal values to fractional form in R?
A fraction form of a decimal value is the form of the value represented with division sign. For example, representing 0.5 as 1 / 2. In R, we can use fractions function of MASS package to convert a decimal value or a vector of decimal values to fractional form. To do so, we just need to pass the value in fractions function as fractions(“Decimal_value or Vector_Of_Decimal_Values”).
Loading MASS package −
Examples
> library(MASS)
Output
> fractions(0.14) [1] 7/50 > fractions(1.14) [1] 57/50 > library(MASS) > fractions(0.5) [1] 1/2 > fractions(0.3) [1] 3/10 > fractions(0.31) [1] 31/100 > fractions(1.31) [1] 131/100 > fractions(2.01) [1] 201/100 > fractions(1.01001) [1] 101001/1e+05 > fractions(4.211) [1] 4211/1000 > fractions(215.11) [1] 21511/100 > fractions(215.15) [1] 4303/20 > fractions(15.77) [1] 1577/100 > fractions(16.73) [1] 1673/100 > fractions(100.07) [1] 10007/100 > fractions(100.17) [1] 10017/100 > fractions(1.17) [1] 117/100 > fractions(2.65) [1] 53/20 > fractions(1.7) [1] 17/10 > fractions(1.65) [1] 33/20 > fractions(78.35) [1] 1567/20 > fractions(43.95) [1] 879/20 > fractions(0.005) [1] 1/200 > fractions(0.025) [1] 1/40 > fractions(0.00625) [1] 1/160 > fractions(1111.1111) [1] 11111111/10000 > fractions(c(0.2,0.07,0.75,0.84,1.35,2.65,7.95)) [1] 1/5 7/100 3/4 21/25 27/20 53/20 159/20 > fractions(c(14.2,798.37,12.75,15.84,1.35,2.65,7.95)) [1] 71/5 79837/100 51/4 396/25 27/20 53/20 159/20
- Related Articles
- How to convert unit of measurements of a value or a vector in R?
- How to truncate a numerical vector to a specified number of decimal places in R?
- Write the number 8 in decimal form and fractional form.
- How to convert a decimal number to a fraction reduced to its lowest form?
- C# Program to convert an Int32 value to a decimal
- Convert a stored MD5 string to a decimal value in MySQL?
- How to convert a decimal into a fraction and a fraction into a decimal?
- How to convert decimal number to a percentage?
- Write a Golang program to convert a binary number to its decimal form
- Write a Golang program to convert a decimal number to its binary form
- How to convert a date or date vector to POSIXct in R?
- How to convert a Decimal to Octal using C#?
- How to convert data frame values to a vector by rows in R?
- Convert 3kg 50g into Decimal Form
- How do we convert binary to decimal and decimal to binary?

Advertisements