-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMerging datasets- select unmatched records.R
38 lines (29 loc) · 1.55 KB
/
Merging datasets- select unmatched records.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
############################### Merging datasets- select unmatched records ############################################################
############################################################################################
#These R Tidyverse code snippets demonstrate how to identify unmatched observations between two
#data frames, "sex" and "ahw," using the anti_join function from the dplyr package.
#Finding Unmatched Observations (sex): The first code snippet uses the anti_join function to
#find unmatched observations in the "sex" data frame compared to the "ahw" data frame. The by
#argument specifies the variable(s) to use for matching, in this case, the "name" variable.
#The resulting "unmatched" data frame includes observations from the "sex" data frame that do
#not have a matching "name" in the "ahw" data frame.
#Finding Unmatched Observations (ahw): The second code snippet reverses the order of the data
#frames in the anti_join function. It identifies unmatched observations in the "ahw" data frame
#compared to the "sex" data frame. Again, the by argument specifies the "name" variable for
#matching. The resulting "unmatched" data frame includes observations from the "ahw" data frame
#that do not have a matching "name" in the "sex" data frame.
library(tidyverse)
sex<-tribble(
~name,~sex,
"Alfred","M",
"Henry","M",
"Mary","F",
)
ahw<-tribble(
~name,~age,~height,~weight,
"Alfred",14,69,112.5,
"Henry",14,63.5,102.5,
"James",12,57.3,83,
)
unmatched<-anti_join(sex,ahw,by=c("name"))
unmatched<-anti_join(ahw,sex,by=c("name"))