how to return number of decimal places in R

前端 未结 12 1179
走了就别回头了
走了就别回头了 2020-12-01 08:25

I am working in R. I have a series of coordinates in decimal degrees, and I would like to sort these coordinates by how many decimal places these numbers have (i.e. I will w

12条回答
  •  天涯浪人
    2020-12-01 08:32

    Another contribution, keeping fully as numeric representations without converting to character:

    countdecimals <- function(x) 
    {
      n <- 0
      while (!isTRUE(all.equal(floor(x),x)) & n <= 1e6) { x <- x*10; n <- n+1 }
      return (n)
    }
    

提交回复
热议问题