itemprop="text">
I'm having trouble with decimals. I
have a vector of numbers, for
example:
x <-
c(400000, 500000, 100000,
97500)
I would like to
turn them like this:
x <-
c(4000.00, 5000.00, 1000.00,
975.00)
I've tried
commands like round
, format
and
options
, but all they do is to add more zeros to these numbers.
How to change the decimal places in the
vector?
Thanks in
advance!
Answer
You could use the function
formatC()
formatC(as.numeric(x/100),
format = 'f', flag='0', digits = 2)
No comments:
Post a Comment