Print less than or equal sign in R?

前端 未结 2 1552
甜味超标
甜味超标 2021-01-27 07:53

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)


        
相关标签:
2条回答
  • 2021-01-27 08:17
    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
    
    0 讨论(0)
  • 2021-01-27 08:19

    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)

    0 讨论(0)
提交回复
热议问题