[R] Formatting summary() output to a file

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Fri Jul 27 17:44:29 CEST 2018


Not quite sure what you mean here.

R is open source, so

> print.summaryDefault  ## at the prompt. It's in base R, so no package::
prefix needed

will give you the code used for formatting. You can then do the same.

Cheers,
Bert







Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

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