How can i find out WHERE the error occurs?
i've got a double loop like this
companies <- # vector with all companies in my data.frame
dates <- # vector with all event dates in my data.frame
for(i in 1:length(companies)) {
events_k <- # some code that gives me events of one company at a time
for{j in 1:nrow(events_k)) {
# some code that gives me one event date at a time
results <- # some code that calculates stuff for that event date
}
mylist[[i]] <- results # store the results in a list
}
In this code I got an error (it was something like error in max(i)...) The inner loop works perfectly. So by leaving out the outer loop and manually enter the company ID's until that error appeared, I found out for which company there was something wrong. My data.frame had letters in a vector with daily returns for that specific company.
For a next time: Is there a way in R to find out WHERE (or here FOR WHICH COMPANY) the error appears? It could save a lot of time!