statsbylopez / BlogPosts

27 stars 14 forks source link

filtering by down #4

Open dlm1223 opened 5 years ago

dlm1223 commented 5 years ago

I think there's a bug in the down filtering in scrapr-data.R? Your blog post has 3rd down Romo to Bryant but that's a 2nd down play in the data?

williamsbenjamin commented 5 years ago

@statsbylopez @dlm1223 I ran into the same problem when running the sample.rp.drive.needs.TD function. The issue is that sample.rp.drive.needs.TD takes a parameter called down, and then within the function uses dplyr::filter(...,down == down,...). dplyr uses lazy eval, so down == down evaluates to all true. Thus, in sample.rp.drive.needs.TD, the function is sampling from all downs with the given yards to go and yards from own goal. I asked this question on stack overflow yesterday (https://stackoverflow.com/questions/58175876/using-the-name-of-a-data-frame-column-as-a-parameter-value-for-a-function-which/58188282#58188282) which helped me figure out the issue. There are easy workarounds, including renaming the down parameter passed to sample.rp.drive.needs.TD.