temp.tc [i]替换中的错误长度为零

时间:2019-03-20 17:17:10

标签: r

我没有编码经验,所以请原谅我在尝试解释此问题时可能犯的任何错误。我有为R编写的代码,应该返回一些曲线。该代码读取一个csv文件作为输入。

我遇到以下错误:

Error in temp.tc[i] <- (as.numeric(unique(unlist(regmatches(dur, temp))))) : 

替换的长度为零

这似乎是给我错误的代码部分:

for(i in seq (1,rl,1))
{
dur <- ddf[[c]][i] #steps through each cell in the duration column
dur1 <- toString(dur)  #converts the cell into a string
dur2 <- unlist(strsplit(dur1, split="")) #splits the string into individual characters
dur3 <- strtoi(dur2[1]) #converts the characters back into integers

#If a value is found, proceed through if statements to identify key words 
if(is.na(dur3)== FALSE)
{
temp <- gregexpr("[0‐9]+", dur)  #removes strings from duration

#checks if duration has units of minutes 
if(grepl(min, dur) == TRUE)
{
  #removes words from the cell and stores duration (minutes) into a vector 
  temp.tc[i] <- (as.numeric(unique(unlist(regmatches(dur, temp)))))
  n1 <- append(n1, i)
}

#checks if duration has units of hours
if((grepl(hr, dur) == TRUE) || (grepl(ho, dur) == TRUE))
{
  #removes words from the cell and stores duration (minutes) into a vector 
  temp.tc[i] <- (as.numeric(unique(unlist(regmatches(dur, temp)))))*60
  n2 <-i
}

#checks if duration has units of days 
if(grepl(day, dur) == TRUE)
{
  #removes words from the cell and stores duration (minutes) into a vector 
  temp.tc[i] <- (as.numeric(unique(unlist(regmatches(dur, temp)))))*24*60 
  n2 <-i #defines row where duration ends
}
}
}

我非常感谢您提供有关解决此问题的提示!

谢谢。

0 个答案:

没有答案