Hi,
Welcome to the RStudio community!
Here is an example of what you can do. I used dummy data, but you will need to load in your Excel files of course.
library(tidyverse)
#Get the data (this is dummy data)
#In your case you read from excel with for example readxl::read_excel()
file1 = data.frame(
id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
colA = c("a","b","c","d","e","f","g","h","i","j"),
result = c(0.936,0.031,0.57,0.882,0.847,0.981,
0.854,0.66,0.274,0.578)
)
file2 = data.frame(
id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 11L, 9L, 10L),
result = c(0.936,0.031,0.57,0.882,0.847,0.981,
0.854,0.66,0.272,0.578)
)
#Only keep columns needed
file1 = file1 %>% select(id, result)
#Join the data together (full join)
allData = full_join(file1, file2, by = "id")
allData
#> id result.x result.y
#> 1 1 0.936 0.936
#> 2 2 0.031 0.031
#> 3 3 0.570 0.570
#> 4 4 0.882 0.882
#> 5 5 0.847 0.847
#> 6 6 0.981 0.981
#> 7 7 0.854 0.854
#> 8 8 0.660 NA
#> 9 9 0.274 0.272
#> 10 10 0.578 0.578
#> 11 11 NA 0.660
#Compare results
allData %>%
mutate(identical = result.x == result.y)
#> id result.x result.y identical
#> 1 1 0.936 0.936 TRUE
#> 2 2 0.031 0.031 TRUE
#> 3 3 0.570 0.570 TRUE
#> 4 4 0.882 0.882 TRUE
#> 5 5 0.847 0.847 TRUE
#> 6 6 0.981 0.981 TRUE
#> 7 7 0.854 0.854 TRUE
#> 8 8 0.660 NA NA
#> 9 9 0.274 0.272 FALSE
#> 10 10 0.578 0.578 TRUE
#> 11 11 NA 0.660 NA
#Compare results with rounding
allData %>%
mutate(identical = round(result.x,2) == round(result.y, 2))
#> id result.x result.y identical
#> 1 1 0.936 0.936 TRUE
#> 2 2 0.031 0.031 TRUE
#> 3 3 0.570 0.570 TRUE
#> 4 4 0.882 0.882 TRUE
#> 5 5 0.847 0.847 TRUE
#> 6 6 0.981 0.981 TRUE
#> 7 7 0.854 0.854 TRUE
#> 8 8 0.660 NA NA
#> 9 9 0.274 0.272 TRUE
#> 10 10 0.578 0.578 TRUE
#> 11 11 NA 0.660 NA
Created on 2021-08-11 by the reprex package (v2.0.0)
All of this was done by functions from the tidyverse (the dplyr package). You can learn more about it here.
Hope this helps,
PJ
.