我试图在多个不同的数据集中求和大于70的值。我相信,聚合可以做到这一点,但是我的研究并未指出一种明显的解决方案来获得超过70个数据集的值。我首先使用聚合来获取每日最大值,并将这些值放入称为Yearmaxs的数据框中。这是我的代码以及我尝试过的内容:
Sys.setenv(TZ = "UTC")
library(openair)
library(lubridate)
filedir <- "C:/Users/dfmcg/Documents/Thesisfiles/8hravg"
myfiles <- c(list.files(path = filedir))
paste(filedir, myfiles, sep = '/')
npsfiles <- c(paste(filedir, myfiles,sep = '/'))
for (i in npsfiles[22]) {
x <- substr(i,45,61)
y <- paste('C:/Users/dfmcg/Documents/Thesisfiles/exceedenceall', x, sep='/')
timeozone <- import(i, date="DATES", date.format = "%Y-%m-%d %H", header=TRUE, na.strings="NA")
overseventy <- c()
yearmaxs <- aggregate(rolling.O3new ~ format(as.Date(date)), timeozone, max)
colnames(yearmaxs) <- c("date", "daymax")
overseventy <- aggregate(daymax ~ format(as.Date(date)), yearmaxs, FUN = length,
subset = as.numeric(daymax) > 70)
colnames(overseventy) <- c("date", "daymax")
aggregate(daymax ~ format(as.Date(date), "%Y"), overseventy, sum)
我也尝试过:sum>“ 70 and sum(daymax>” 70)。
在这一点上,我的另一个想法是使用for循环遍历值。我希望a可以再次使用聚合来求和感兴趣的值。任何帮助将不胜感激!
我想你要:
aggregate(daymax ~ format(as.Date(date)), yearmaxs, FUN = length,
subset = as.numeric(daymax) > 70)
要的东西:
as.numeric(daymax) > 70
不要使用daymax > "70"
;subset
参数aggregate.formula
。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句