I'm hoping to take the set difference between 40 dataframes (10 years of data each with 4 quarters) starting with the second quarter of my first year and comparing it to the first quarter of my first year, all the way to my last quarter. I have all my dataframes in a list, but can't figure out the loop.
short <- list(q4_17, q1_18, q2_18, q3_18, q4_18)
for(i in short)
{j=i+1
new<- j %>%
filter(PATID %in% setdiff(j,i)$PATID)
}
I'm getting the error: Error in FUN(left, right): nun-numeric argument to binary operator.
Thanks for any suggestions. I would try to put my dataframes up but the code is on a remote desktop and difficult to get off.
In addition to the comments above, two more problems:
newwhich each pass of theforloop, so you will only benefit from the last pass, all previous passes will be silently discarded.i+1(treating it as an index) works up untiliindicates the last frame withinshort, at which point the "next frame inshort" is an indexing error.To appease both issues, we can do either of these, assuming that the setdiff/filter code actually does everything you need.
Judging by what you may be doing, I feel there is a better way to do this setdiff/filter part.