Home > OS >  How to value part of character value with another variable in R
How to value part of character value with another variable in R

Time:12-15

I have x1 <- 5, x2 <- "this number is " variables.

Is there a way to write it like this? (without using paste() function) x3 <- "this number 'x1' " and give result "this number is 5 "

CodePudding user response:

The cat function will do it:

cat(x2, x1)
#this number is  5

The cat function is different than the print function in many ways but the two biggest in my mind are that cat returns NULL and does not quote by default, whereas print returns its first argument and does quote by default. The cat function is used entirely for its side-effect of output to a device. print on the other hand is often used as a way of both returning a value and put text to a device.

  •  Tags:  
  • r
  • Related