Guest User

Untitled

a guest
Feb 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. > as.numeric("1.560,65")
  2. [1] NA
  3. Warning message:
  4. NAs introduced by coercion
  5.  
  6. > as.numeric("1.560")
  7. [1] 1.56
  8. > as.numeric("1.560")>2
  9. [1] FALSE
  10.  
  11. as.numeric(gsub(",", "\.", gsub("\.","", "1.560,65")))
  12. [1] 1560.65
  13.  
  14. formatC(1560.65, format = "f", big.mark = ".", decimal.mark = ",")
  15. [1] "1.560,6500"
  16.  
  17. str_numbers <- c("1.560,65", "134,2","123","0,32")
  18. as.numeric(gsub(",", "\.", gsub("\.", "", str_numbers)))
  19.  
  20. > (tmp <- gsub("\.", "", str_numbers))
  21. [1] "1560,65" "134,2" "123" "0,32"
  22. > gsub(",", "\.", tmp)
  23. [1] "1560.65" "134.2" "123" "0.32"
  24.  
  25. nums <- c("1.560,65", "134,2","123","0,32")
  26.  
  27. library(readr)
  28. parse_number(nums, locale = locale(decimal_mark = ','))
  29.  
  30. [1] 1560.65 134.20 123.00 0.32
Add Comment
Please, Sign In to add comment