refine_original %>%
+ mutate(company=replace(company, grepl("ps",company), "phillips")) %>%
+ as.data.frame()
Error in replace(company, grepl("ps", company), "phillips") :
object 'company' not found
我不知道为什么它没有找到错误对象。
> str(refine_original)
'data.frame': 25 obs. of 6 variables:
$ company : Factor w/ 19 levels "ak zo","akz0",..: 10 8 7 13 11 9 3 4 5 2 ...
$ Product.code...number: Factor w/ 23 levels "p-23","p-34",..: 4 3 19 20 17 1 13 11 22 2 ...
$ address : Factor w/ 25 levels "Delfzijlstraat 54",..: 9 10 11 12 13 14 19 20 21 22 ...
$ city : Factor w/ 1 level "arnhem": 1 1 1 1 1 1 1 1 1 1 ...
$ country : Factor w/ 1 level "the netherlands": 1 1 1 1 1 1 1 1 1 1 ...
$ name : Factor w/ 20 levels "dhr j. Gansen",..: 7 6 1 9 4 5 2 10 3 8 ...
请帮忙
答案 0 :(得分:0)
您的代码中包含额外的+
个符号。删除它们然后错误应该消失:
refine_original %>%
mutate(company=replace(company, grepl("ps",company), "phillips")) %>%
as.data.frame()