全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1096 1
2017-08-01
mydata$运营商<-if(grepl("移动",mydata$产品名称)){运营商<-"移动"}else {if(grepl("电信",mydata$产品名称)){运营商<-"电信"}else {运营商<-"联通"}}

结果是:所有变量值均为联通
Warning messages:
1: In if (grepl("移动", mydata$产品名称)) { :
  the condition has length > 1 and only the first element will be used
2: In if (grepl("电信", mydata$产品名称)) { :
  the condition has length > 1 and only the first element will be used

是哪里有问题 ?应该怎么修改?


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2017-8-3 11:36:46
已解决
ifelse:  mydata_1$运营商<-ifelse(grepl("联通",mydata_1$产品名称),"联通",ifelse(grepl("移动",mydata_1$产品名称),"移动","电信"))
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群