我可以使用以下代码将一列转换为climdexInput对象格式:
tmax.dates <- as.PCICt(do.call(paste, t[,c("year",
"days")]), format="%Y %j", cal="gregorian")
tmin.dates <- as.PCICt(do.call(paste, t[,c("year",
"days")]), format="%Y %j", cal="gregorian")
prec.dates <- as.PCICt(do.call(paste, t[,c("year",
"days")]), format="%Y %j", cal="gregorian")
## Load the data in.
ci <- climdexInput.raw(tmax=ntuobs[,1],
tmin=ntuobs[,1],
prec=ntuobs[,1],tmax.dates, tmin.dates, prec.dates, base.range=c(2000, 2010))
## Create a timeseries of monthly maximum 5-day consecutive
然而,ntuobs []有100列,我想在所有100列上应用该函数,然后将其存储到100个ci [,]列中。
“我尝试申请循环
for (i in 1:100){
ci[,i] <- climdexInput.raw(tmax=ntuobs[,i],
tmin=ntuobs[,i],
prec=ntuobs[,i],tmax.dates, tmin.dates, prec.dates, base.range=c(2000, 2010))
} "
但这会产生错误
"Error in ci[, i] <- climdexInput.raw(tmax = changi[, i], tmin = ntuobs[, :
object of type 'S4' is not subsettable"
请建议我解决这个问题的方法。任何使用APPLY函数的循环方法都是受欢迎的。 谢谢
示例数据集
library(PCICt)
## Create a climdexInput object from some data already loaded in and
## ready to go.
## Parse the dates into PCICt.
tmax.dates <- as.PCICt(do.call(paste, ec.1018935.tmax[,c("year",
"jday")]), format="%Y %j", cal="gregorian")
tmin.dates <- as.PCICt(do.call(paste, ec.1018935.tmin[,c("year",
"jday")]), format="%Y %j", cal="gregorian")
prec.dates <- as.PCICt(do.call(paste, ec.1018935.prec[,c("year",
"jday")]), format="%Y %j", cal="gregorian")
## Load the data in.
ci <- climdexInput.raw(ec.1018935.tmax$MAX_TEMP,
ec.1018935.tmin$MIN_TEMP, ec.1018935.prec$ONE_DAY_PRECIPITATION,
tmax.dates, tmin.dates, prec.dates, base.range=c(1971, 2000))
## Create a timeseries of annual SDII values.
sdii <- climdex.sdii(ci)
但这是针对单个列的,但我的数据是100列(整体)。