我想知道是否可以在控制台(Rstudio)中显示cat(...)
“并且还将文件保存在< strong> .txt
格式?
这是我的R代码:
SOS = 33
df = 12
cat("\n","-------------", "\n" ,"SOS "," df","\n", "-------------","\n",
SOS," ",df,"\n", "-------------", file = "Output.txt" )
答案 0 :(得分:1)
SOS = 33
df = 12
#prepare your output
x = paste("\n","-------------", "\n" ,"SOS "," df","\n", "-------------","\n",
SOS," ",df,"\n", "-------------", sep = "")
#display in console
cat(x)
#-------------
#SOS df
#-------------
#33 12
#-------------
#Write to a txt file
cat(x, file = "output.txt")