Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dplyr summarize output - how to save it

Tags:

r

dplyr

I need to calculate summary statistics for observations of bird breeding activity for each of 150 species. The data frame has the species (scodef), the type of observation (codef)(e.g. nest building), and the ordinal date (days since 1 January, since the data were collected over multiple years). Using dplyr I get exactly the result I want.

library(dplyr)
library(tidyr)
phenology %>% group_by(sCodef, codef) %>%
  summarize(N=n(), Min=min(jdate), Max=max(jdate), Median=median(jdate)) 
# A tibble: 552 x 6
# Groups:   sCodef [?]
   sCodef codef     N   Min   Max Median
   <fct>  <fct> <int> <dbl> <dbl>  <dbl>
 1 ABDU   AY        3   172   184   181 
 2 ABDU   FL       12   135   225   188 
 3 ACFL   AY       18   165   222   195 
 4 ACFL   CN        4   142   156   152.
 5 ACFL   FL       10   166   197   192.
 6 ACFL   NB        6   139   184   150.
 7 ACFL   NY        6   166   207   182 
 8 AMCO   FL        1   220   220   220 
 9 AMCR   AY       53    89   198   161 
10 AMCR   FL       78   133   225   166.
# ... with 542 more rows

How do I get these summary statistics into some sort of data object so that I can export them to use ultimately in a Word document? I have tried this and gotten an error. All of the many explanations of summarize I have reviewed just show the summary data on screen. Thanks

 out3 <- summarize(N=n(), Min=min(jdate), Max=max(jdate), median=median(jdate))
Error: This function should not be called directly
like image 540
jwoods48 Avatar asked Aug 30 '25 16:08

jwoods48


1 Answers

Assign this to a variable, then write to a csv like so:

summarydf <- phenology %>% group_by......(as above)

write.csv(summarydf, filename="yourfilenamehere.csv")
like image 143
Luke Hayden Avatar answered Sep 02 '25 05:09

Luke Hayden