Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I type the +- symbol in R

Tags:

symbols

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?

like image 361
wen Avatar asked Aug 17 '14 05:08

wen


1 Answers

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 (%)"
like image 121
MrFlick Avatar answered Sep 19 '22 14:09

MrFlick