Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何编写一个在一行中打印输出的函数?像这样:
> x<-c(1,2,3,4) > f(x) [1] mean=2.5 sd=1.290994
我从用另一种语言编写的应用程序中使用 R,我需要计算的值在同一行中。
不用写函数,R中已经存在,调用c
c
> c(mean=mean(x), sd=sd(x)) mean sd 2.500000 1.290994
cat如果您希望结果在一行中,是另一种选择
cat
> cat("mean =", mean(x), "sd =", sd(x)) mean = 2.5 sd = 1.290994