I wanted to compare two tables. If the value of table 2 placed in 0.3 tolerance (+0.3 and -0.3) of the table 2 call it normal otherwise call it abnormal.
Sample Data:
Table 1.
0.17666667
-0.2413333
-0.179666
0.182437
0.012229
0.127333
-0.1180
0.8873
1.24100
1.5213
Table 2.
-1.6
-0.5
-0.4
-0.4
-0.2
2.5
0.6
2.2
2.3
1.3
Expected results for first row:
if 0.17666667**-0.3**<-1.6<0.17666667**+0.3**
result NORMAL Otherwise Abnormal
Example 1: Check Whether Two Data Frames are Equal Using identical() Function. The RStudio console returns the logical value TRUE, i.e. our two data frames data1 and data2 are the same. This time, the RStudio console prints the logical value FALSE, i.e. data1 and data3 are not the same.
Compare two tables by using joins. To compare two tables by using joins, you create a select query that includes both tables. If there is not already an existing relationship between the tables on the fields that contain the corresponding data, you create a join on the fields that you want to examine for matches.
You could also do this with all.equal
.
table.1 <- scan(text="
0.17666667
-0.2413333
-0.179666
0.182437
0.012229
0.127333
-0.1180
0.8873
1.24100
1.5213")
table.2 <- scan(text="
-1.6
-0.5
-0.4
-0.4
-0.2
2.5
0.6
2.2
2.3
1.3")
are.close <- function(x, y, tol) isTRUE(all.equal(x, y, tol))
close <- mapply(are.close, x=table.1, y=table.2, tol=0.3)
result <- ifelse(close, 'N', 'A')
# [1] "A" "N" "N" "A" "N" "A" "A" "A" "A" "N"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With