How can we print H₂O in R? And, I am not looking for labels sub/superscripted in plots. I want to run:
cat("H2O")
And see H₂O
How can we print H₂O in R? And, I am not looking for labels sub/superscripted in plots. I want to run:
cat("H2O")
And see H₂O
Using a one-liner with the UTF-8 character for subscript 2:
paste0("H", "\u2082", "O")
[1] "H₂O"
The UTF-8 character for subscript two as an R string literal is "\u2082
.
Note that if your R console/tool be already UTF-8 enabled, then you should simply be able to use a literal string, e.g.
"H₂O"
[1] "H₂O"