Skip to content

Instantly share code, notes, and snippets.

@giacecco
Created July 27, 2015 09:35
Show Gist options
  • Save giacecco/c10aa1a290673e3c5614 to your computer and use it in GitHub Desktop.
Save giacecco/c10aa1a290673e3c5614 to your computer and use it in GitHub Desktop.
# a few useful functions...
is.even <- function(x) sum(x %% 2 == 0) == length(x)
is.odd <- function(x) sum(x %% 2 != 0) == length(x)
# and finally, the calculation
can_be_inferred <- sum(apply(lrpp_streets_for_inference, 1, function (row) {
aons <- lrpp_addresses_with_numeric_aon[(lrpp_addresses_with_numeric_aon$street == row[1]) & (lrpp_addresses_with_numeric_aon$pcd == row[2]), "aon"]
# if all numbers I know are odd or even, I can only infer the missing odd and even numbers,
# otherwise I can infer all
# TODO: crazy below: why row[3] and row[4] are not numeric any longer?
inferred <- setdiff(seq(from = as.numeric(row[3]), to = as.numeric(row[4]), by = ifelse(is.even(aons) | is.odd(aons), 2, 1)), aons)
return(length(inferred))
}))
> can_be_inferred
[1] 190285
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment