[R] Formatting summary() output to a file
William Dunlap
wdun|@p @end|ng |rom t|bco@com
Fri Jul 27 17:40:49 CEST 2018
Try
cat(sep="\n", file=con, capture.output(summary(...)))
capture.output(x) return character vector whose elements contain
the lines of text that would have been printed by print(x).
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Fri, Jul 27, 2018 at 8:20 AM, Rich Shepard <rshepard using appl-ecosys.com>
wrote:
> I want to save the output of summary(df_name) to a disk file and my
> research found that the sink() function is what I want to use. The 'R
> Cookbook'
> provides a an alternative example using cat() to a connection. Here,
>
> con <- file("wysumallyrs.txt", "w")
> cat(summary(wyallyrs), file=con)
> close(con)
>
> produces this output:
>
> Length:402531 Class :character Mode :character NA NA NA NA
> Length:402531 Class :character Mode :character NA NA NA NA Min.
> :90.65 1st Qu.:93.81 Median :94.14 Mean :93.86 3rd Qu.:94.43
> Max. :98.91 NA's :225 Min. :1988-10-01 1st Qu.:1996-02-01 Median
> :2001-12-01 Mean :2002-07-28 3rd Qu.:2008-09-10 Max. :2018-06-21
> NA Min. :1988-10-01 00:30:00 1st Qu.:1996-02-01 00:45:00 Median
> :2001-12-01 15:30:00 Mean :2002-07-29 03:04:28 3rd Qu.:2008-09-10
> 16:00:00 Max. :2018-06-21 00:00:00 NA
>
> Is there a way to format this output as it is on the console when the
> script contains
>
> sum <- summary(wyallyrs)
> print(sum)
>
> date time elev myDate
> Length:402531 Length:402531 Min. :90.65 Min. :1988-10-01
> Class :character Class :character 1st Qu.:93.81 1st Qu.:1996-02-01
> Mode :character Mode :character Median :94.14 Median :2001-12-01
> Mean :93.86 Mean :2002-07-28
> 3rd Qu.:94.43 3rd Qu.:2008-09-10
> Max. :98.91 Max. :2018-06-21
> NA's :225
> myTime
> Min. :1988-10-01 00:30:00
> 1st Qu.:1996-02-01 00:45:00
> Median :2001-12-01 15:30:00
> Mean :2002-07-29 03:04:28
> 3rd Qu.:2008-09-10 16:00:00
> Max. :2018-06-21 00:00:00
>
> TIA,
>
> Rich
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list