library(dplyr)
glimpse(full_dat)
Observations: 9,720
Variables: 6
$ Product <chr> "Apple iPhone 4s 8GB Unlocked GSM Smartphone w/ S...
$ Brand <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N...
$ Price <dbl> 115, 115, 115, 115, 115, 115, 115, 115, 115, 115,...
$ Rating <dbl> 5, 1, 4, 5, 5, 3, 5, 5, 5, 1, 5, 5, 1, 5, 2, 5, 5...
$ Reviews <chr> "It was new and at a great price! Phone came real...
$ Votes <dbl> 2, 1, 0, 1, 2, 2, 2, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0...
我想更改变量的值
Product
伪代码:
glimpse(full_dat)
Observations: 9,720
Variables: 6
$ Product <chr> "iPhone 4s", "iPhone 4s", "iPhone 4s", "iphone 4s...
$ Brand <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N...
$ Price <dbl> 115, 115, 115, 115, 115, 115, 115, 115, 115, 115,...
$ Rating <dbl> 5, 1, 4, 5, 5, 3, 5, 5, 5, 1, 5, 5, 1, 5, 2, 5, 5...
$ Reviews <chr> "It was new and at a great price! Phone came real...
$ Votes <dbl> 2, 1, 0, 1, 2, 2, 2, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0...
我读了一篇类似的文章,其中提出了以下解决方案。
full_dat %>%
mutate_at(vars(contains('iphone 4s')), funs(.=='ipohne 4s'))
但是,这在我的情况下不起作用,即值保持不变。
product = c(full_dat$Product[1:5])
dput(product)
c("Apple iPhone 4s 8GB Unlocked GSM Smartphone w/ Siri, iCloud and 8MP Camera - Black",
"Apple iPhone 4s 8GB Unlocked GSM Smartphone w/ Siri, iCloud and 8MP Camera - Black",
"Apple iPhone 4s 8GB Unlocked GSM Smartphone w/ Siri, iCloud and 8MP Camera - Black",
"Apple iPhone 4s 8GB Unlocked GSM Smartphone w/ Siri, iCloud and 8MP Camera - Black",
"Apple iPhone 4s 8GB Unlocked GSM Smartphone w/ Siri, iCloud and 8MP Camera - Black"
)