Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如果列文本中缺少短语,则使用短语列表示例创建列_R - Fatal编程技术网

R 如果列文本中缺少短语,则使用短语列表示例创建列

R 如果列文本中缺少短语,则使用短语列表示例创建列,r,R,目标 我有一个短语列表。我还有一个数据框,其中一列包含文本。 我想在dataframe中创建一个新列,其中包含短语列表样本的(随机数),只要该短语不在dataframe列中 输入数据帧: structure(list(report = c("Biopsies of small bowel mucosa including Brunner's glands", "These are fragments of small bowel mucos

目标

我有一个短语列表。我还有一个数据框,其中一列包含文本。 我想在dataframe中创建一个新列,其中包含短语列表样本的(随机数),只要该短语不在dataframe列中

输入数据帧:

structure(list(report = c("Biopsies of small bowel mucosa including Brunner's glands",
                            "These are fragments of small bowel mucosa which include Brunner's glands ",
                            "These are fragments of small bowel mucosa which include Brunner's glands There is no evidence of coeliac disease in these biopsies",
                            "There is coeliac disease here. ",
                            "Biopsies of specialisd gastric mucosa with moderate acute and active inflammation.",
                            "These are fragments of small bowel mucosa. The small bowel fragments are within normal limits"
  )), .Names = "report", row.names = c(NA, 6L), class = "data.frame")
c("active inflammation", "coeliac disease","Brunner's glands")
 Phrase                                                                                                                                  List sample
Biopsies of small bowel mucosa including Brunner's glands                                                                             active inflammation
These are fragments of small bowel mucosa which include Brunner's glands                                                              active inflammation,coeliac disease
These are fragments of small bowel mucosa which include Brunner's glands There is no evidence of coeliac disease in these biopsies    active inflammation
There is coeliac disease here.                                                                                                        Brunner's glands
Biopsies of specialisd gastric mucosa with moderate acute and active inflammation                                                     coeliac disease,Brunner's glands
These are fragments of small bowel mucosa. The small bowel fragments are within normal limits                                         active inflammation
输入列表:

structure(list(report = c("Biopsies of small bowel mucosa including Brunner's glands",
                            "These are fragments of small bowel mucosa which include Brunner's glands ",
                            "These are fragments of small bowel mucosa which include Brunner's glands There is no evidence of coeliac disease in these biopsies",
                            "There is coeliac disease here. ",
                            "Biopsies of specialisd gastric mucosa with moderate acute and active inflammation.",
                            "These are fragments of small bowel mucosa. The small bowel fragments are within normal limits"
  )), .Names = "report", row.names = c(NA, 6L), class = "data.frame")
c("active inflammation", "coeliac disease","Brunner's glands")
 Phrase                                                                                                                                  List sample
Biopsies of small bowel mucosa including Brunner's glands                                                                             active inflammation
These are fragments of small bowel mucosa which include Brunner's glands                                                              active inflammation,coeliac disease
These are fragments of small bowel mucosa which include Brunner's glands There is no evidence of coeliac disease in these biopsies    active inflammation
There is coeliac disease here.                                                                                                        Brunner's glands
Biopsies of specialisd gastric mucosa with moderate acute and active inflammation                                                     coeliac disease,Brunner's glands
These are fragments of small bowel mucosa. The small bowel fragments are within normal limits                                         active inflammation
我的预期输出:

structure(list(report = c("Biopsies of small bowel mucosa including Brunner's glands",
                            "These are fragments of small bowel mucosa which include Brunner's glands ",
                            "These are fragments of small bowel mucosa which include Brunner's glands There is no evidence of coeliac disease in these biopsies",
                            "There is coeliac disease here. ",
                            "Biopsies of specialisd gastric mucosa with moderate acute and active inflammation.",
                            "These are fragments of small bowel mucosa. The small bowel fragments are within normal limits"
  )), .Names = "report", row.names = c(NA, 6L), class = "data.frame")
c("active inflammation", "coeliac disease","Brunner's glands")
 Phrase                                                                                                                                  List sample
Biopsies of small bowel mucosa including Brunner's glands                                                                             active inflammation
These are fragments of small bowel mucosa which include Brunner's glands                                                              active inflammation,coeliac disease
These are fragments of small bowel mucosa which include Brunner's glands There is no evidence of coeliac disease in these biopsies    active inflammation
There is coeliac disease here.                                                                                                        Brunner's glands
Biopsies of specialisd gastric mucosa with moderate acute and active inflammation                                                     coeliac disease,Brunner's glands
These are fragments of small bowel mucosa. The small bowel fragments are within normal limits                                         active inflammation
我已经试过了

  Final$mine<-ifelse(grepl(paste(ListCheck, collapse='|'), Final[,1], ignore.case=TRUE),print("Check here"),sample(ListCheck,replace=T))

Final$mine您可以首先检查哪些输入不存在,即(调用数据
df

输入列表