Question

I've done a bunch of calculations in R, and now need to turn my data.frame into a table of mean +/- SD in MS Word (that's the required format). But, I have no idea how to get a "+/-" symbol; it seems like there ought to be a way to do this that does not involve inserting the symbol manually into each cell of the table in Word.

Here's an example using the mtcars data:

require(reshape2)
test_avg <- dcast(mtcars, cyl+gear ~ ., value.var = "mpg", fun.aggregate = mean)
test_sd <- dcast(mtcars, cyl+gear ~ ., value.var = "mpg", fun.aggregate = sd)
testtable <- cbind(test_avg[ , 1:2], paste(as.matrix(round(test_avg[3], 1)), as.matrix(round(test_sd[3], 1)), sep="+/-"))
write.csv(testable, file="Table.csv")

One can then open "Table.csv" in Excel, and copy, paste special into Word and get a nice table. This is great, but would be much better if I could put something in the "sep = " argument that would give me a "+/-" symbol in Word. Any ideas?

Thanks!

Was it helpful?

Solution

Use unicode symbol 00B1.

mysymbol <- "\u00B1"
foo <- cbind(test_avg[ , 1:2], paste(as.matrix(round(test_avg[3], 1)), 
          as.matrix(round(test_sd[3], 1)), sep= mysymbol))

> foo
  cyl gear      dev
1   4    3  21.5±NA
2   4    4 26.9±4.8
3   4    5 28.2±3.1
4   6    3 19.8±2.3
5   6    4 19.8±1.6
6   6    5  19.7±NA
7   8    3 15.1±2.8
8   8    5 15.4±0.6
> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top