문제

I am a beginner in R, and currently for my output I use:

print("Hello World!")

However, I would like to give something like this out:

x <- 1
print("Hello World!" + x)#the + x does not 

How can such a thing be coded in R?

I appreciate your answer!

도움이 되었습니까?

해결책

Use cat:

cat("Hello World!", x, '\n')

(Note the trailing '\n', otherwise no newline character will be appended.)

Alternatively, you can combine the print statement with a formatting statement (sprintf);

cat(sprintf('Hello World!%s\n', x))

The formatting syntax of sprintf corresponds to that in C. The documentation linked above has more information.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top