RStudio: simple calculations vs. separator [duplicate] - r

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=",");

Related

What does "?" mean in Erlang? [duplicate]

This question already has answers here:
Erlang: What does question mark syntax mean?
(3 answers)
Closed 2 years ago.
I see alot of code in erlang with a question mark before it, what does it mean? Is it Macros or can it be used in another way? Example:
{Total, Pids} = run(10, 20),
?assertEqual(200, Total),
?assert(processes_stopped(Pids)).
or:
?MODULE
When you try call macros, you need add in start of name ‘?’. Notes: the macros can create with or without arguments.

Extract information from string with dots as separator in R [duplicate]

This question already has answers here:
How to use the strsplit function with a period
(3 answers)
Closed 5 years ago.
I apologize for possible similar questions, but I just can't find the solution for my problem. So, I have a string with three parts, separated by “.”, for example:
a <- "XXX.YY.ZZZ"
(the length of strings differ, it could also be a <- "XXXX.Y.ZZ", but the three parts are always separated by the two “.”.
I solved the problem for the first part:
library(stringi)
stri_extract(a, regex='[^.]*')
[1] "XXX"
Appreciate your help.
hello you can use strsplit as follows
strsplit(a,"\\.")[[1]]

R - Weird behavior of grepl [duplicate]

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

creating string of numbers seperated by commas [duplicate]

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"

R displays numbers in scientific notation [duplicate]

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);

Resources