Hi I have a dataframe with names and some numbers. The number in column 't1' should be unique for each person but there are some cases they are not. So I want to find those rows where one number in column 't1' corresponds to two different person, so that I can remove those data from my dataframe for future analysis.
This is some toy data that looks like my original data:
name t1 t2 t3
1 John Doe 1 a a
2 Doe John 1 a a
3 John Doe A 1 b b
4 David Freeman 2 b b
5 Freeman David 2 b b
6 Jack Chen 3 b b
7 John Chen 3 b b
8 Chris Baker F 4 b b
9 Baker O Chris 4 b b
>
And this is the desired output:
name t1
1 Jack Chen 3
2 John Chen 3
3 Chris Baker F 4
4 Baker O Chris 4
The following are my code and output I get:
bio_share_id <- bio %>%
distinct(name, t1, .keep_all = T) %>%
group_by(t1) %>%
filter(n() > 1) %>%
ungroup() %>%
select(c(name,t1))
name t1
<chr> <chr>
1 John Doe 1
2 Doe John 1
3 John Doe A 1
4 David Freeman 2
5 Freeman David 2
6 Jack Chen 3
7 John Chen 3
8 Chris Baker F 4
9 Baker O Chris 4
As you can see, my code is reading each name as unique variable whenever there are some variations in name formats. It's reading John Doe, Doe John, and John Doe A all as different person but I want it to read them as one person.
Since the original data I have is so big, I can't fix the names manually so I want to find a way to clean those names using R. John Doe, Doe John, and John Doe A should be treated as one individual, but Chris Baker F and Bake O Chris should be treated as two different unique individual.
Thanks in advance!