2

I am creating a simple data frame of inputted values and I want the values to maintain the digits and decimal places I inputted. Instead, R is increasing decimal places for some of the inputted values.

Inputting values:

k       = 100
lambda  = 0.006
b       = 1
a       = 0.0005

Creating Data Frame:

parameter_df <- data.frame("Parameter" = c("a", "b", "k", "λ"), 
                           "Value" = c(a, b, k, lambda))

Output:

a   0.0005          
b   1.0000          
k   100.0000            
λ   0.0060

I would like the output to read the same as the inputted values

a   0.0005          
b   1           
k   100         
λ   0.006
OTStats
  • 1,820
  • 1
  • 13
  • 22
  • 3
    Not possible unless you use characters. The vector will always have the decimal places of the element with the most digits. – Rich Scriven Jan 22 '19 at 19:50
  • 4
    Numbers in R don't have different numbers of digits; they all have the exact same (they are either stored as floating point numbers or integers). If you need to keep track of the number of digits something has, you'll need to store a character/string version of the number since that's really a purely visual representation of a number as far as a computer is concerned. So you could store an additional column to keep track of how many digits you want to track for each value. But the R parser isn't able to remember how many digits were there originally when you type a numeric literal value. – MrFlick Jan 22 '19 at 19:50
  • Okay, thank you. It's not a big problem--I can just deal with what I have. Thank you for your comments! – Kaitlyn Browning Jan 22 '19 at 19:55

0 Answers0