Ошибка в замене temp.tc [i] имеет нулевую длину - PullRequest
0 голосов
/ 20 марта 2019

У меня нет опыта программирования, поэтому прошу прощения за любые ошибки, которые я могу сделать, пытаясь объяснить эту проблему.У меня есть код, написанный для 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
}
}
}

Буду очень признателен за советы по устранению неисправностей!

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...