0

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  
Papang
  • 1
  • 1
  • 2
  • 1
    Can you edit your question to include the output of `sessionInfo()`? I cannot reproduce your issue on my machine, so I'm wondering what difference in our setup causes this. – duckmayr Nov 08 '18 at 15:19
  • This is my locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 (you may need to do that) – hrbrmstr Nov 09 '18 at 13:26

2 Answers2

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
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • I (+1)'d, but I still don't know how to explain **why** this is occurring for OP; it doesn't happen on my machine (as demonstrated below). – duckmayr Nov 08 '18 at 15:17
  • It has to be locale-related. – hrbrmstr Nov 08 '18 at 15:44
  • Still does not work.. If I use view(table), I can see the less than or equal to sign, but if I just use print(table), there is no sign there.. – Papang Nov 09 '18 at 13:21
2

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)

duckmayr
  • 16,303
  • 3
  • 35
  • 53