Hello,
So recently in another Topic I received some guidance on putting together a code to help run a comparison of two files, filtered down to specific items of interest. The goal of the code is to be able to QC vast amounts of data with an output of True/False if the values match. I have a couple variations of the code that all work (differing scenarios), however one possible scenario is that the values of one file are rounded and the other is not.
The code for this works for the most part, however I notice it throws up a few false errors (saying things do not match when they should) sometimes when the value of comparison contains a x.5. After some research this, I believe, is the integrated "Round to the nearest even" standard that is only found in coding and statistics. To start, please do not get into the "oh this is the way it is" argument. I totally understand the validity of it for statistics, and am not arguing that point. What I am looking for is some help integrating a code into my function that would essentially make it not do this, instead following the "normal" rule for rounding that has been learned coming up since grade school.
First time using reprex in this format, so will edit after posting if it looks weird. The dataset I am using is:
data.frame(
stringsAsFactors = FALSE,
Barcode = c("621175209036","621175209037",
"621175209038","621175209039","621175209136",
"621175209137","621175209138","621175209139","621175209633",
"621175209634","621175209635","621175209636",
"621175209733","621175209734","621175209735","621175209736",
"621175210333","621175210334","621175210335",
"621175210336"),
Result.x = c("157.86","6931.095","43.938",
"<2.34","<31.26","5623.703","65.535","<2.34",
"<31.26","5319.741","28.478","<2.34","257.009","3241.802",
"55.961","<2.34","198.521",">24000","60.129",
"<2.34"),
Result.y = c("157.9","6931.1","43.9",
"<2.34","<31.26","5623.7","65.5","<2.34","<31.26",
"5319.7","28.5","<2.34","257.0","3241.8","56.0","<2.34",
"198.5",">24000","60.1","<2.34")
)
#> Barcode Result.x Result.y
#> 1 621175209036 157.86 157.9
#> 2 621175209037 6931.095 6931.1
#> 3 621175209038 43.938 43.9
#> 4 621175209039 <2.34 <2.34
#> 5 621175209136 <31.26 <31.26
#> 6 621175209137 5623.703 5623.7
#> 7 621175209138 65.535 65.5
#> 8 621175209139 <2.34 <2.34
#> 9 621175209633 <31.26 <31.26
#> 10 621175209634 5319.741 5319.7
#> 11 621175209635 28.478 28.5
#> 12 621175209636 <2.34 <2.34
#> 13 621175209733 257.009 257.0
#> 14 621175209734 3241.802 3241.8
#> 15 621175209735 55.961 56.0
#> 16 621175209736 <2.34 <2.34
#> 17 621175210333 198.521 198.5
#> 18 621175210334 >24000 >24000
#> 19 621175210335 60.129 60.1
#> 20 621175210336 <2.34 <2.34
Created on 2021-08-16 by the reprex package (v2.0.0)
The code I am looking to hopefully modify is:
myData %>%
+ mutate(identical = round(as.numeric(Result.x,1)) == round(as.numeric(Result.y, 1)))
#> Error in myData %>% +mutate(identical = round(as.numeric(Result.x, 1)) == : could not find function "%>%"
Created on 2021-08-16 by the reprex package (v2.0.0)
Any help or advise would be greatly appreciated on finding a workaround for this. Like I said before, I understand and appreciate the rounding standard, but for the sake of a comparison I need rounding to behave "normally".
-Q