arsenal
arsenal copied to clipboard
Strings composed of only numbers are not compared as expected
Whats the issue Strings composed of only numbers are converted to numeric types
Use case
I have a set of GPS points stored as character that are required to have a certain level of precision. In some instances, lat/long values will end with 1 or more zeros. When data were entered, the trailing zeros were sometimes omitted and need to be updated. (e.g. data entered as 1 instead of 1.0000). I use a corrections log to update the data (changing 1 to 1.0000) and then use the comparedf
function to make sure all changes have been made. However, when evaluating the difference between the original and the updated data, "1"
and "1.0000"
are treated as the same. So when I check if the expected number of changes were made the output from comparedf
provides an undercount.
Reproducible example
old_df <- data.frame(a = as.character(1:10))
new_df <- old_df |>
dplyr::mutate(a = sprintf("%.*f",6,as.numeric(a)))
arsenal::comparedf(new_df,old_df)