-1
我試圖生成的日期/時間的順序與此代碼的整數倍,但我不斷收到錯誤項目替換數不是更換長度
「錯誤all_dates [週期, 1] < - 糊(c_dates [A], 「 - 」,c_hours並[b], 「H」):項替換的數目不更換 長度」
使用的代碼的倍數這個:
years <- c(2009, 2010, 2011, 2012, 2013) #1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006)
months <- c(6, 7, 8, 9)
for (i in years)
{
upper.bound<- paste("01", months[1], i, sep="-")
lower.bound <- paste("30", months[4], i, sep="-")
c_dates <- seq(as.Date(upper.bound, "%d-%m-%Y"), as.Date(lower.bound, "%d-%m-%Y"), "days")
c_hours <- c(0, seq(0:22))
len <- dim(as.matrix(c_dates))[1]*dim(as.matrix(c_hours))[1]
all_dates <- data.frame()
all_dates <- seq(0,0,length.out=len)
dim(all_dates) <- c(dim(as.matrix(c_dates))[1]*dim(as.matrix(c_hours))[1], 1)
cycle <- 1
for(a in c_dates)
{
for(b in c_hours)
{
all_dates[cycle, 1] <- paste(c_dates[a], "-", c_hours[b], "h")
cycle <- cycle + 1
}
}
}
任何想法可能是錯誤的?
什麼'months'?和'我'。您的代碼在第一行失敗。 – Spacedman
另外,'all_dates'的價值是什麼? –
對不起,忘了幾行代碼。所有相關的東西都在那裏:) –