如何在r中单行打印文本和变量

时间:2022-05-23 21:45:49

Is there a way to print text and variables in a single line in r

有没有办法在r中的单行中打印文本和变量

eg

a="Hello"
b="EKA"
c="123456"

print("$a !! my name is $b and my number is $c")

out put will be like this

out put会是这样的

Hello !! my name is EKA and my number is 123456

1 个解决方案

#1


10  

I'd suggest using sprintf function. The advantage of this function is, that the variables can be of any class (here, c is numeric).

我建议使用sprintf函数。这个函数的优点是,变量可以是任何类(这里,c是数字)。

a="Hello"
b="EKA"
c=123456

sprintf("%s !! my name is %s and my number is %i", a, b, c)

#1


10  

I'd suggest using sprintf function. The advantage of this function is, that the variables can be of any class (here, c is numeric).

我建议使用sprintf函数。这个函数的优点是,变量可以是任何类(这里,c是数字)。

a="Hello"
b="EKA"
c=123456

sprintf("%s !! my name is %s and my number is %i", a, b, c)