```
Error in dat$methrs[j] <- second_factor * second_position_time :
replacement has length zero
for (j in 1:length(dat$time)) {
if (is.na(dat$methrs[j]) & (dat$wear_day[j] %in% good_days)) {
mets <- dat$methrs[j - 1] / (dat$interval[j - 1] / 3600)
first_position_time <- as.numeric(difftime(dat$time[j], dat$time[j - 1],
units = "hours"))
second_position_time <- as.numeric(difftime(dat$time[j + 1], dat$time[j],
units = "hours"))
totaltime <- dat$interval[j - 1]
first_factor <- (first_position_time / totaltime) * mets
second_factor <- (second_position_time / totaltime) * mets
dat$methrs[j - 1] <- first_factor * first_position_time
dat$methrs[j] <- second_factor * second_position_time
} else {
dat$methrs[j] <- dat$methrs[j]
}
}
```

Not sure what to do with this error message. I'm trying to build graphs from my data.