How to use the value of variables in expressions in R?

I am relatively new to R. How to use the value of variables in print and other operators. For example, in Java we can do this:

System.out.println(" My name is "+ pradeep); 

We use the + operator. How to do it in R?

+4
source share
3 answers

In R, you can do this with paste() (see ?paste for more information):

 print(paste("My name is ", pradeep, ".", sep = "")) 
+3
source

In general, you should prefer Henrik to answer, but note that you can specify lines with sprintf .

 name <- c("Richie", "Pradeep") sprintf("my name is %s", name) 
+1
source

Assuming

 pradeep <- "Pradeep" 

Try the following:

 cat("My name is", pradeep, "\n") 

In addition, the gsubfn package has the ability to add any quly perl-style line interpolation to any command, previously using the fn$ command

 library(gsubfn) fn$cat("My name is $pradeep\n") fn$print("My name is $pradeep") 

There is also sprintf and paste , as mentioned by others.

+1
source

Source: https://habr.com/ru/post/1336288/


All Articles