在R中交换两个数字的子集数据帧
我在下面提到了datafram:在R中交换两个数字的子集数据帧,r,stringdist,R,Stringdist,我在下面提到了datafram: df <- read.table(text = "code Num mail identifier U_id YY-12 12345 jjf@gmail.com ar145j U-111 YY-13 12345 jjf@gmail.com Ra145J U-111 YY-14 48654 ert
df <- read.table(text =
"code Num mail identifier U_id
YY-12 12345 jjf@gmail.com ar145j U-111
YY-13 12345 jjf@gmail.com Ra145J U-111
YY-14 48654 ert@gmail.com at188R U-112
YY-15 48654 Ert@gmail.com At819R U-113
YY-16 88994 fty@ymail.com fr789U U-114
YY-17 88994 fty@ymail.com Rf789X U-115
YY-18 14500 foi@ymail.com xr747Y U-116
YY-19 14500 foi@ymail.com xY747C U-117", header = T)
也许这会有帮助
library(tidyverse)
library(stringi)
df %>%
group_by(Num, mail) %>%
filter(n() == 1 | toupper(first(substr(identifier, 1, 2))) ==
stri_reverse(toupper(last(substr(identifier, 1, 2)))))
# A tibble: 6 x 5
# Groups: Num, mail [4]
# code Num mail identifier U_id
# <fct> <int> <fct> <fct> <fct>
#1 YY-12 12345 jjf@gmail.com ar145j U-111
#2 YY-13 12345 jjf@gmail.com Ra145J U-111
#3 YY-14 48654 ert@gmail.com at188R U-112
#4 YY-15 48654 Ert@gmail.com At819R U-113
#5 YY-16 88994 fty@ymail.com fr789U U-114
#6 YY-17 88994 fty@ymail.com Rf789X U-115
库(tidyverse)
图书馆(stringi)
df%>%
分组依据(数量,邮件)%>%
过滤器(n()==1 | toupper(第一个(substr(标识符,1,2)))==
反斜线(最后一个(子线(标识符,1,2‘‘‘)’))
#一个tibble:6x5
#组:Num,mail[4]
#代码Num邮件标识符U\U id
#
#1 YY-12 12345jjf@gmail.comar145j U-111
#2 YY-13 12345jjf@gmail.comRa145J U-111
#3 YY-14 48654ert@gmail.comat188R U-112
#4 YY-1548654Ert@gmail.comAt819R U-113
#5 YY-1688994fty@ymail.comfr789U-114
#6 YY-17 88994fty@ymail.comRf789X U-115
library(tidyverse)
library(stringi)
df %>%
group_by(Num, mail) %>%
filter(n() == 1 | toupper(first(substr(identifier, 1, 2))) ==
stri_reverse(toupper(last(substr(identifier, 1, 2)))))
# A tibble: 6 x 5
# Groups: Num, mail [4]
# code Num mail identifier U_id
# <fct> <int> <fct> <fct> <fct>
#1 YY-12 12345 jjf@gmail.com ar145j U-111
#2 YY-13 12345 jjf@gmail.com Ra145J U-111
#3 YY-14 48654 ert@gmail.com at188R U-112
#4 YY-15 48654 Ert@gmail.com At819R U-113
#5 YY-16 88994 fty@ymail.com fr789U U-114
#6 YY-17 88994 fty@ymail.com Rf789X U-115