concatenate two characters in a print() in r

To concatenate two characters in a print() statement in R, you can use the paste() or paste0() function. Here is an example:

main.r
x <- "Hello"
y <- "world!"
print(paste(x, y))
# Output: [1] "Hello world!"

# The `paste0()` function is a shorthand version of `paste()` with the separator argument set to an empty string
print(paste0(x, y))
# Output: [1] "Helloworld!"
237 chars
9 lines

Alternatively, you can also use the concatenation operator %+%:

main.r
print(x %+% y)
# Output: [1] "Hello world!"
44 chars
3 lines

Note that the cat() function can also be used to print concatenated strings without any separation or newline characters.

gistlibby LogSnag