0
请参阅下面的代码。代码并不显示准确的价值,因为它在新的变种标题设置为“其他”的一切:错误的输出如果然后在R中的其他语句
哪里是问题extractTitle<- function(name){
name<-as.character(name)
if (length(grep("Miss.",name))>0){
return("Miss.")
}else if (length(grep("Master.",name))>0){
return("Master.")
}else if (length(grep("Mrs.",name))>0){
return("Mrs.")
}else if (length(grep("Mr.",name))>0){
return("Mr.")
}else {
return("Other")
}
}
titles<- NULL
for (i in 1:nrow(data.combined)){
titles<- c(titles,extractTitle(data.combined[i,"name"]))
}
data.combined$title<- as.factor(titles)
请咨询。
你可以提供'data.combined'使用?或者它的一部分,最好使用'dput' – zyurnaidi