我正在计算城市首尔的average_relative_humidity,日期是2020-01-01 tll 2020-31-01。我有这样的数据:

我已经试过了,但我真的不知道该怎么做。
Seoul_weather_dt <- Corona_relevant_weather_dt[, avg_relative_humidity_seoul := mean(avg_relative_humidity[code =="2020-01-01":"2020-01-01"]), by = c("province", "date", "avg_temp", "avg_relative_humidity"]有人能帮我吗?
发布于 2020-12-16 18:10:42
像这样的东西?
#select only Seoul and relevant dates
Seoul_weather_dt <- Corona_relevant_weather_dt[province == "Seoul" & date > as.date("2020-01-01") & date <= as.date("2020-31-01")]
#calculate average humidity for each unique date
aggregate(Seoul_weather_dt$avg_relative_humidity, by = list(Seoul_weather_dt$date), FUN = mean)您提供的代码行相当长。我建议创建多行,每行具有较少的函数,以维护概述(当遇到错误时也更容易)。也是
date”类中的Date吗?您可以看到,使用str(Seoul_weather_dt)code =="2020-01-01":"2020-01-01"仅选择一天by = c("province", "date", "avg_temp", "avg_relative_humidity")是很奇怪的。然后,您还将计算avg_relative_humidity的每个观测值的平均值,这不是您想要的,https://stackoverflow.com/questions/65320739
复制相似问题