在R中打印小于或等于符号?

时间:2018-11-08 15:07:08

标签: r

我尝试将 \ u2264 用作小于或等于符号:

> 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
> ...

如果我单击查看表,则会出现:

> 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
> ...

还有其他方法可以打印此标志吗?

根据要求:

> 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  

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

我无法重现此问题:

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

reprex package(v0.2.1)于2018-11-08创建