Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print numeric values with a string in R [duplicate]

Tags:

r

I have a integer that has been assigned to a variable, I want to print that to the console but i get an error. Code and sample below

number <- 64
print("I want to print this number: " + number)

But instead I get the message: "Error: non-numeric argument to binary operator" I want to see something like

[1] "I want to print this number: 64"
like image 239
user1605665 Avatar asked Oct 28 '25 13:10

user1605665


1 Answers

Use sprintf

sprintf("I want to print this number: %i", number)
#[1] "I want to print this number: 64"

or paste0

paste0("I want to print this number: ", number)
#[1] "I want to print this number: 64"
like image 125
Jota Avatar answered Oct 31 '25 05:10

Jota