How to set ',' as decimal separator with R

后端 未结 3 1662
陌清茗
陌清茗 2021-01-04 10:29

Even though my Windows 7 locale settings specify using \",\" as a decimal separator, R and RStudio give me a \".\" separator. Is there any way to change this? Note the \"LC_

3条回答
  •  囚心锁ツ
    2021-01-04 11:09

    Based on the fact that you want to use it with (Pandoc) markdown as far as I can see from the blog comment where you referenced this question, I would also suggest to give a try to my pander package:

    > library(pander)
    > panderOptions('decimal.mark', ',')
    > panderOptions('table.split.table', Inf)
    > pander(head(iris))
    
    -------------------------------------------------------------------
     Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
    -------------- ------------- -------------- ------------- ---------
         5,1            3,5           1,4            0,2       setosa  
    
         4,9             3            1,4            0,2       setosa  
    
         4,7            3,2           1,3            0,2       setosa  
    
         4,6            3,1           1,5            0,2       setosa  
    
          5             3,6           1,4            0,2       setosa  
    
         5,4            3,9           1,7            0,4       setosa  
    -------------------------------------------------------------------
    

    Or PHP Markdown Extra syntax for easier usage with knitr:

    > pandoc.table(head(iris), style = 'rmarkdown')
    
    
    |  Sepal.Length  |  Sepal.Width  |  Petal.Length  |  Petal.Width  |  Species  |
    |:--------------:|:-------------:|:--------------:|:-------------:|:---------:|
    |      5,1       |      3,5      |      1,4       |      0,2      |  setosa   |
    |      4,9       |       3       |      1,4       |      0,2      |  setosa   |
    |      4,7       |      3,2      |      1,3       |      0,2      |  setosa   |
    |      4,6       |      3,1      |      1,5       |      0,2      |  setosa   |
    |       5        |      3,6      |      1,4       |      0,2      |  setosa   |
    |      5,4       |      3,9      |      1,7       |      0,4      |  setosa   |
    

提交回复
热议问题