Print less than or equal sign in R?

2019-08-22 10:50发布

I tried using \u2264 for the less than or equal sign:

> names(table_A1) <- c("x", "P(X=x)", "P(X\u2264x)")
> print(table_A1)

but this appears in the output:

>    x P(X=x) **P(X=x)**
> 1  2  0.562  0.563
> 2  3  0.281  0.844
> 3  4  0.105  0.949
> 4  5  0.035  0.984
> ...

while if I click view table this appears:

> x P(X=x) **P(X≤x)**
> 1 2 0.562 0.563
> 2 3 0.281 0.844
> 3 4 0.105 0.949
> ...

Is there any other way that I can print this sign?

As requested:

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1    yaml_2.2.0  

标签: r
2条回答
仙女界的扛把子
2楼-- · 2019-08-22 11:04

I cannot reproduce this issue:

table_A1 <- read.table(header = FALSE, text = "2  0.562  0.563
3  0.281  0.844
4  0.105  0.949
5  0.035  0.984")
names(table_A1) <- c("x", "P(X=x)", "P(X\u2264x)")
print(table_A1)
#>   x P(X=x) P(X≤x)
#> 1 2  0.562  0.563
#> 2 3  0.281  0.844
#> 3 4  0.105  0.949
#> 4 5  0.035  0.984
# Try @hrbrmstr's way
colnames(mtcars)[1] <- as.character(expression("P(X\u2264x)"))
head(mtcars[,1:3])
#>                   P(X≤x) cyl disp
#> Mazda RX4           21.0   6  160
#> Mazda RX4 Wag       21.0   6  160
#> Datsun 710          22.8   4  108
#> Hornet 4 Drive      21.4   6  258
#> Hornet Sportabout   18.7   8  360
#> Valiant             18.1   6  225
# Works
# Try how you're doing it
colnames(mtcars)[1] <- "P(X\u2264x)"
head(mtcars[,1:3])
#>                   P(X≤x) cyl disp
#> Mazda RX4           21.0   6  160
#> Mazda RX4 Wag       21.0   6  160
#> Datsun 710          22.8   4  108
#> Hornet 4 Drive      21.4   6  258
#> Hornet Sportabout   18.7   8  360
#> Valiant             18.1   6  225
# works

Created on 2018-11-08 by the reprex package (v0.2.1)

查看更多
虎瘦雄心在
3楼-- · 2019-08-22 11:15
colnames(mtcars)[1] <- as.character(expression("P(X\u2264x)"))
head(mtcars[,1:3])
##                   P(X≤x) cyl disp
## Mazda RX4           21.0   6  160
## Mazda RX4 Wag       21.0   6  160
## Datsun 710          22.8   4  108
## Hornet 4 Drive      21.4   6  258
## Hornet Sportabout   18.7   8  360
## Valiant             18.1   6  225
查看更多
登录 后发表回答