wen
wen

Reputation: 1935

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?

Upvotes: 9

Views: 19973

Answers (1)

MrFlick
MrFlick

Reputation: 206197

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 (%)"

Upvotes: 18

Related Questions