[英]Using r, how can I apply a function (moments::skewness) that is not a basic aggregate function to a group-by table?
I have in Redshift a set of crowdsourced weather data: many stations, each many days, each day 20 to 100 observations, each observation several variables. 我在Redshift中有一组众包的天气数据:许多站点,每隔几天,每天20到100个观测值,每个观测值有几个变量。 I am computing daily statistics. 我正在计算每日统计数据。 It works like this; 它是这样工作的;
dailyn<-cwoparchive %>%
filter(stationname=="EW2020" %>%
group_by (archivedate) %>%
summarise(ncount=n(),meanlat=mean(latitude),meanlon=mean(longitude)) %>%
collect() %>%
data.frame ()
returns this, just what I want: 返回此,正是我想要的:
Next I want to know if mornings are sunnier. 接下来,我想知道早晨是否晴天。 But when I do the same thing as above, only replacing that summarise line with this one: 但是,当我执行与上述相同的操作时,仅用该内容替换该摘要行:
summarise(askew=skewness(linterpreted))
I get an error message, "Error in postgresqlExecStatement(conn, statement, ...) : RS-DBI driver: (could not Retrieve the result : ERROR: function skewness(integer) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts." Yet the skewness function works fine on the same data in normal, non-grouped data frames. 我收到错误消息,“ postgresqlExecStatement(conn,statement,...)中的错误:RS-DBI驱动程序:(无法检索结果:错误:函数偏斜度(整数)不存在)提示:没有函数与给定名称匹配和参数类型。您可能需要添加显式类型转换。”但是,偏度函数在正常的非分组数据帧中的相同数据上可以正常工作。
With apologies for bothering everybody, I worked it out. 道歉打扰大家,我解决了。 First download, secondly group-by in a follow-on step - this seems irrational but it is necessary, and then summarise on that. 首先下载,然后在后续步骤中进行分组-这似乎不合理,但这是必要的,然后在此进行总结。
stationdata<-cwoparchive %>%
filter(stationname=="EW2020") %>%
collect() %>%
data.frame ()
station_by_day <- group_by(stationdata, archivedate)
skew_by_day <- summarise(station_by_day, count = n(),askew=skewness(linterpreted))
produces the ideal result: 产生理想的结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.