for(i in 1:length(hotdogs$Country)){
if(hotdogs$Country[i]=="United States"){
hotdogs$Country[i]<- c("#821122")}
else{hotdogs$Country[i] <- c("#cccccc")}
}
如果数据量比较大的话这样比较耗时间,建议用:
Country<- hotdogs$Countryindex<- Country=="United States"
Country[index]<- "#821122"
index1<-Country!="United States"
Country[index1]<- "#cccccc"
print(Country)
虽然比较简单,但是速度较快。。。