[英]How to assign a cat() value to an object in r
I have a character vector that I would like to process some functions on it.我有一个字符向量,我想在它上面处理一些函数。
vars <- c("1234_AS_SA1_PCNS","2345_AS_SA2_UDA", "3823_AS_SA3_CL")
cat(dQuote(paste0("Equal = ", paste("(", vars, ", Slope[0])",
collapse=",\n ", sep=""), ";"), FALSE))
The above procedure prints this:上面的过程打印:
"Equal = (1234_AS_SA1_PCNS, Slope[0]),
(2345_AS_SA2_UDA, Slope[0]),
(3823_AS_SA3_CL, Slope[0]);"
My question is that how can I save this character variable in an object?我的问题是如何将这个字符变量保存在一个对象中?
When I assigned this procedure to an object,当我将此过程分配给一个对象时,
aa <- cat(dQuote(paste0("Equal = ", paste("(", vars, ", Slope[0])",
collapse=",\n ", sep=""), ";"), FALSE))
I get aa NUll:我得到一个空:
> aa
NULL
Any thoughts?有什么想法吗? Thanks!谢谢!
cat
doesn't have a return
value. cat
没有return
值。 It just print
.它只是print
。 We could write the output to a file by specifying the file
argument我们可以通过指定file
参数将输出写入file
cat(dQuote(paste0("Equal = ", paste("(", vars, ", Slope[0])",
collapse=",\n ", sep=""), ";"), FALSE),
file = 'file.txt')
The dQuote
output can be assigned and not the cat
wrapped on it可以分配dQuote
输出,而不是包裹在它上面的cat
aa <- dQuote(paste0("Equal = ", paste("(", vars, ", Slope[0])",
collapse=",\n ", sep=""), ";"), FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.