我正在尝试使用 tidyr 扩展函数,但我想传入我自己的特征名称向量以用于关键参数。
例如,默认用法是
test<-data.frame(id=c(1,1,2,2),
feat=c("feat1", "feat2", "feat1", "feat2"),
value = c(10,20, 1000, 2000))
test %>% spread(key = feat, value = value, fill = 0)
id feat1 feat2
1 1 10 20
2 2 1000 2000
我想传入我自己的特征字符串向量作为键,就像这样。
featlist<-c("feat1", "feat2", "feat3")
test %>% spread(key = featlist, value = value, fill = 0)
#desired output
id feat1 feat2 feat3
1 1 10 20 0
2 2 1000 2000 0
#Error output
Error: `var` must evaluate to a single number or a column name, not a character vector
#Trying spread_
test %>% spread_(key = featlist, value = "value", fill = 0)
Error: Only strings can be converted to symbols