-2

I have a vector with values such as 0.953, 0.952, 0.07555 .. I just want to keep the first two decimal values. In other words, I just want to transform the above list as 0.95, 0.95, 0.08.How to do this in R?

user288609
  • 12,465
  • 26
  • 85
  • 127

1 Answers1

0

Here is one approach.

Idea borrowed from Formatting Decimal places in R

# A useful function that you can use anytime. 
specify_decimal <- function(x, k) format(round(x, k), nsmall=k)

data <- c(0.953, 0.952, 0.07555)

specify_decimal(x=data, k= 2) 
[1] "0.95" "0.95" "0.08"
Community
  • 1
  • 1
Jd Baba
  • 5,948
  • 18
  • 62
  • 96