如果与R中第二列中的任何单元格匹配,则指定单个单元格值
我目前正在尝试指定普通诊所的医生和其他医疗服务提供者。我想为此创建一个新列,并执行以下操作如果与R中第二列中的任何单元格匹配,则指定单个单元格值,r,R,我目前正在尝试指定普通诊所的医生和其他医疗服务提供者。我想为此创建一个新列,并执行以下操作 如果上一列说明其GP预约,请将GP放入新列 如果上一列说明其其他HCP预约,请将其他HCP放入新列中 若在前一列中有一个空白条目,则查看第二个data.frame中包含已知GP预约的列表。如果它与该列中的任何条目匹配,则指定为GP 如果前一列中有空白条目,请查看第二个data.frame中包含已知其他HCP预约的列表。如果它与该列中的任何条目匹配,则指定为Other HCP 我试着这样做。请注意,appt
GP
放入新列其他HCP
放入新列中data.frame
中包含已知GP预约的列表。如果它与该列中的任何条目匹配,则指定为GP
data.frame
中包含已知其他HCP预约的列表。如果它与该列中的任何条目匹配,则指定为Other HCP
appts
是数据。frame
我想将GP
或其他HCP
放入,而GP appts
和ohcp appts
是预约列表,允许我指定条目是否为空
appts$hcpdesignation <-NA
appts$hcpdesignation [appts$hcpcat == "GP"] <- "GP"
appts$hcpdesignation [appts$hcpcat == "Other HCP"] <- "Other HCP"
appts$hcpdesignation [appts$V11 == "" & appts$V10 == gpappts$apptype] <- "GP"
appts$hcpdesignation [appts$V11 == "" & appts$V10 == ohcpappts$apptype] <- "Other HCP"
appts$hcpdesignation1:我想你在找接线员
2:我不知道为什么要在前两个测试中测试列hcpcat
,然后在后两个测试中测试列V11
。您的分步说明要求对所有4个测试测试“上一列”。我以为那是个错误
## generate data
set.seed(2L);
div <- sample(c(T,F),10L,T);
N <- 20L;
gpappts <- data.frame(apptype=letters[1:10][div],stringsAsFactors=F);
ohcpappts <- data.frame(apptype=letters[1:10][!div],stringsAsFactors=F);
appts <- data.frame(hcpcat=sample(c('GP','Other HCP',''),N,T),V10=sample(letters[1:12],N,T),stringsAsFactors=F);
##生成数据
结实种子(2L);
div1:我想你在找接线员
2:我不知道为什么要在前两个测试中测试列hcpcat
,然后在后两个测试中测试列V11
。您的分步说明要求对所有4个测试测试“上一列”。我以为那是个错误
## generate data
set.seed(2L);
div <- sample(c(T,F),10L,T);
N <- 20L;
gpappts <- data.frame(apptype=letters[1:10][div],stringsAsFactors=F);
ohcpappts <- data.frame(apptype=letters[1:10][!div],stringsAsFactors=F);
appts <- data.frame(hcpcat=sample(c('GP','Other HCP',''),N,T),V10=sample(letters[1:12],N,T),stringsAsFactors=F);
##生成数据
结实种子(2L);
div
## results
gpappts;
## apptype
## 1 a
## 2 d
## 3 g
## 4 i
ohcpappts;
## apptype
## 1 b
## 2 c
## 3 e
## 4 f
## 5 h
## 6 j
appts;
## hcpcat V10 hcpdesignation
## 1 Other HCP a Other HCP
## 2 GP b GP
## 3 j Other HCP
## 4 GP k GP
## 5 Other HCP g Other HCP
## 6 h Other HCP
## 7 k <NA>
## 8 GP d GP
## 9 Other HCP i Other HCP
## 10 GP b GP
## 11 Other HCP l Other HCP
## 12 Other HCP d Other HCP
## 13 b Other HCP
## 14 GP b GP
## 15 Other HCP l Other HCP
## 16 Other HCP j Other HCP
## 17 GP l GP
## 18 Other HCP e Other HCP
## 19 g GP
## 20 GP j GP