This question already has answers here:
Line break in expression()?
(2 answers)
Closed 2 years ago.
I want to make a legend title reading
CO₂-text1
text2
Since paste()/paste0() doesn't seem to work on expression I also tried using bquote() instead, but can't figure a way to add the new line. My most succesfull attempt so far:
expression("CO"[2]*"-text1 \n"*" text2")
, which results in
-text1
CO₂ text2
expression(atop("CO"[2]~"text1",text2))
solved the issue (see question-comments).
Related
This question already has an answer here:
grepl not searching correctly in R
(1 answer)
Closed 6 years ago.
I want to know if there is a certain string contained in another string. This works fine here:
grepl("a","a")
However, what I actually want to test is the following and this one doesn't work:
grepl("is.na(x)","is.na(x)")
Can anyone help?
You can escape the special characters like this:
grepl("is\\.na\\(x\\)","is.na(x)")
[1] TRUE
This question already has answers here:
Creating a comma separated vector
(6 answers)
Closed 6 years ago.
I am trying to create a comma separated string exactly like this to put in a url: 1,2,3,4,5 but when I try: paste0(1:5,sep=",") it returns: [1] "1," "2," "3," "4," "5," The spaces are causing issues. How do I get rid of them?
This is not the same question as: this SO post the solution is almost the same, but the question approaches it from a different angle. My question is trying to suppress the spaces, the linked question wants them.
Try to use collapse="," instead of sep=",":
paste0(1:5,collapse=",")
[1] "1,2,3,4,5"
This question already has answers here:
How can I reverse the order of lines in a file?
(24 answers)
Closed 7 years ago.
I need to print a file, but from the last line to the first.
I think I can append a number to the beginning of each line, sort descending, and then remove the line numbers, but there's probably some more elegant way to do that. is there?
You can use tac command
(tac- cat spelled backwards...)
This question already has answers here:
How can I paste 100000 without it being shortened to 1e+05? [duplicate]
(3 answers)
Closed 9 years ago.
The result of function was displayed in scientific notation, I want to change it back to normal, but only for that function, I don't want to change the global setting. Can anyone help?
You can do:
format(functionResult, scientific=FALSE);
or:
as.integer(functionResult);
This question already has answers here:
Comma separator for numbers in R?
(4 answers)
Closed 4 years ago.
I often use RStudio for a simple calculations, something like the following
> (3.456+4.008)*13000+1000000
[1] 1097032
And my question (rather stupid, I assume, but I haven't find an answer) is if it's possible to make the output more friendly? E.g.:
> (3.456+4.008)*13000+1000000
[1] 1'097'032
At the prompt:
?format
As an example
format(12345.6789, digits=9, decimal.mark=",");