dplyr汇总输出-如何保存 [英] dplyr summarize output - how to save it

查看:134
本文介绍了dplyr汇总输出-如何保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算摘要统计信息,以观察150种鸟类中每一种的鸟类繁殖活动。数据框包含物种(scodef),观察类型(codef)(例如筑巢)和顺序日期(自1月1日以来的天数,因为数据已收集多年)。使用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

如何将这些摘要统计信息转换为某种数据对象,以便导出它们以最终在Word文档中使用?我已经尝试过了,但遇到了错误。我查看过的所有摘要的所有解释都只是在屏幕上显示摘要数据。谢谢

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


推荐答案

将其分配给变量,然后像这样写入CSV:

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

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

write.csv(summarydf, filename="yourfilenamehere.csv")

这篇关于dplyr汇总输出-如何保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆