我有大量的气体排放数据。对于48个单独的处理(盆)(每个都有多次测量)我试图计算该气体总排放曲线下面积。然而,AUC只给出曲线下的一个区域,当我尝试定义它给出48个单独的估计时,它不允许它专门显示错误消息'Error:unexpected'='in“for(i = “'脚本后 “for(i = 1:48)”
然后继续说我没有定义。
我该如何解决这个问题?
mydata=cbind(time,erate)
newdata <- subset(mydata, time>=0)
install.packages("zoo")
library(zoo)
#specifying the new data subset and the main variables for the area under curve calculations
newdata=data.frame(newdata)
yy=newdata$erate
xx=newdata$time
id <- order(xx)
#using trapezium figures and roll mean from zoo package to estimate AUC
AUC <- sum(diff(xx[id])*rollmean(yy[id],2))
#defining the deferent variables
aucpot = integer(48)
aucauc = numeric(48)
auctype = integer(48)
aucslurry= integer(48)
aucsoil= integer(48)
# AUC gives one value but I want 48
#trying to define i as the first 48 pots (out of 56) so that I will get an AUC for each pot
for (i=1:48) {
set=subset(rc, time>=0 & pot==i)
yy=set$erate
xx=set$time
id <- order(xx)
(AUC <- sum(diff(xx[id])*rollmean(yy[id],2)))
aucpot[i]=i
}
auc = data.frame(cbind(aucpot, aucauc, auctype, aucslurry, aucsoil)
答案 0 :(得分:0)
R中的for循环语法为:
for(var in sequence) {
expression
}
请注意使用in
而不是=
。
所以您的循环应如下所示:
for (i in 1:48) {...