简体   繁体   中英

How can I type the +- symbol in R

I need to use a heading that includes Mean +- SD. So far, I can only get this:

"Mean +- SD or N (%)"
[1] "Mean +- SD or N (%)"

How can I directly use the "+-" symbol? You know the one character, not two.

Just for the future, how about other symbols, like Greek letter and so on?

I'm assuming you're going to be putting these on a plot. If that's the case, then be sure to check out the ?plotmath help page. In your example, you could use

plot(1,1,main=expression(paste("Mean", phantom(.)%+-%phantom(.), "SD or N (%)")))

If you're just taking about plain text output, that depends on the encoding you have set up on your GUI. And how you type that in would depend on your operating system. You can include the unicode escape code in a string

x<-"Mean \u00b1 SD or N (%)"
Encoding(x)<-"UTF-8"
x
#[1] "Mean ± SD or N (%)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM