x = 12345
cputime = 12.23455
print(x) 결과 -> 12345
print(x+100) 결과 -> 12445
print("이것은 결과입니다.") 결과 -> "이것은 결과입니다."
paste
print("결과:", x) 결과 -> 에러뜸 (문자와 숫자가 같이 쓰여서 에러뜸, 이런 경우 아래와 같이 paste를 써줘야함)
print(paste("결과:", x)) 결과 -> "결과: 12345"
print(paste("CPU time:",cputime,"seconds")) 결과 -> "CPU time: 12.23455 seconds"
paste0
print(paste0("CPU time:",cputime,"seconds")) 결과 -> "CPU time:12.23455seconds"
print(paste0("CPU time: ",cputime," seconds")) ##paste0을 써서 직접 띄어쓰기를 넣어줌 결과 -> "CPU time: 12.23455 seconds"
✔︎
(quote=FALSE)
를 옵션으로 넣으면 ""가 없어짐.print(paste("CPU time:",cputime,"seconds"),quote=FALSE) ## FALSE는 대문자로 쓰기 또는 F만 써도 가능함. 결과 -> CPU time: 12.23455 seconds
x = 12345
cputime = 12.23455
cat(x, cputime,"\n") ## \n는 Enter를 의미함 결과 -> 12345 12.23455
cat(x,"\n", cputime) 결과 -> 12345 12.23455
cat(x+100,"\n") 결과 -> 12445
cat("이것은 결과입니다. \n") 결과 -> 이것은 결과입니다.
cat("CPU time:",cputime,"seconds \n") 결과 -> CPU time: 12.23455 seconds
✔︎
\t
은 Tab을 의미함cat(" 1\t 2\t 3\n 4\t 5\t 6\n") 결과 -> 1 2 3 4 5 6
a = 'hello'
b = 12345
c = 12345.1287
sprintf("문자형: %s, 정수형: %d, 실수형: %.3f",a,b,c) 결과 -> "문자형: hello, 정수형: 12345, 실수형: 12345.129"
v = c("성별","수학성적") sprintf("%s은 %s에 따라 차이가 있을 것이다.",v[2],v[1]) 결과 -> "수학성적은 성별에 따라 차이가 있을 것이다."