如何解决从特定数据框列表修改数据框中的值
我有以下数据。frame
df <- c("sauté de boeuf","sauté de boeuf ou sauté de porc","sauté de boeuf ou omelette")
df <- data.frame(df)
motsclés_oeuf <- c("omelette","oeuf","tortilla")
motsclés_oeuf_ME <-> c("Nowords")
oeuf <- cbind(motsclés_oeuf,motsclés_oeuf_ME)
Motsclés_viande_rouge <- c("boeuf","veau")
Motsclés_viande_rouge_ME <- c("canard","dinde")
viande_rouge <- cbind(Motsclés_viande_rouge,Motsclés_viande_rouge_ME)
Motsclés_viande_blanche <- c("poulet","lapin","porc")
Motsclés_viande_blanche_ME <- c("Nowords")
viande_blanche <- cbind(Motsclés_viande_blanche,Motsclés_viande_blanche_ME)
Meat_list <-list(oeuf,viande_rouge,viande_blanche)
classification_function <- function(X,MC,ME){
Xsep<-unlist(strsplit(toupper(X)," OU "));
compteur=0;
for(mot in Xsep){
motsep <- unlist(strsplit(tolower(mot)," "));
motsep <- lapply(motsep,function(x) sub("(.*)s$",'\\1',x));
if(length(which(motsep%in%MC))>=1 && length(which(motsep%in%ME))<=0){compteur <- compteur+1}
}
return(compteur)
}
output <- vector('list',length(Plat_protidique_liste))
for (i in seq_along(Meat_list)){
output[[i]] <- data.frame(apply(df,c(1,2),function(x) classification_function(x,Meat_list[[i]][,1],2])))}
}
但是,我只想将if条件应用于“ viande_rouge”和“ viande_blanche”关键字,而不是“ oeuf”。我应该如何进行?
我应该如何修改if(length(which(motsep%in%MC))>=1 && length(which(motsep%in%ME))<=0){compteur <- compteur+1}
?
谢谢您的帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。