本文介绍了R输出没有[1],如何很好地格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 取任何帮助功能(即?mean ),并意识到它的输出(或至少输出应该能够以相同的方式生成)。 您如何获得输入,对齐/ intendation? 示例: strings 值 是你想在R中输出的东西(当从一个函数调用的时候),你如何使 [1] 消失,并且这些值排成一行?这是比较基本的,请参考 /R-intro.html\"> R介绍以及 help(cat ) help(sprintf) $ c> help(format) 等等。请参阅格式化函数中的示例(数千个)。下面是一个简单的例子: print.summary.fastLm cat(\\\Calc:\\\) print(x $ call) cat x $ residSum) cat(\ n) printCoefmat(x $系数,P.values = TRUE,has.Pvalue = TRUE)位数 cat(\ n残余标准错误:,formatC(x $ sigma,digits = digit),on, formatC cat(Multiple R-squared:,formatC(x $ r.squared,digits = digits),$ df),自由度\\\,sep = ,格式C(x $ adj.r.squared,digits = digits),\\\,sep =)不可见(x)} I know stuff has been posted, but not as complete as what I am looking for.Take any help function (i.e. ?mean), and realise that it's output (or at least output should be able to be generated in the same manner). How do you get enters, alignment/intendation?Example:strings <- c("t", "df", "p-value", "mean of x", "mean of y")values <- c(t, df, pvalue, mean1, mean2)If this would be the things you'd want to output in R (when called from a function), how do you make the [1] disappear, and the values lined up? 解决方案 This is rather elementary, please consult An Introduction to R as well ashelp(cat)help(sprintf)help(format)and many more. See the (literally thousands) of examples in formatting functions. Here is a simple example from one of my packages:print.summary.fastLm <- function(x, ...) { cat("\nCall:\n") print(x$call) cat("\nResiduals:\n") print(x$residSum) cat("\n") printCoefmat(x$coefficients, P.values=TRUE, has.Pvalue=TRUE) digits <- max(3, getOption("digits") - 3) cat("\nResidual standard error: ", formatC(x$sigma, digits=digits), " on ", formatC(x$df), " degrees of freedom\n", sep="") cat("Multiple R-squared: ", formatC(x$r.squared, digits=digits), ",\tAdjusted R-squared: ",formatC(x$adj.r.squared, digits=digits), "\n", sep="") invisible(x)} 这篇关于R输出没有[1],如何很好地格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-13 14:36