根据数据集名称对列进行突变

时间:2019-09-26 03:55:57

标签: r

有人可以建议根据数据集名称对新列进行突变吗?下面是我的代码:

WK20 <- data.frame(cbind(c("A","B","C","D","E"),c("135373","135530","72082","100029","19719"), c("484576.90","476355.44","249807.60","354968.68","67386.69")),stringsAsFactors = F)

WK20 <- WK20 %>%
rename("STORE ID" = X1,
     "TOTAL UNIT" = X2,
     "TOTAL SALES" = X3) %>%
melt(id="STORE ID") %>% 
mutate(WK = names(data.frame()))

预期的输出将是WK对象中的数据集名称。我运行代码,并收到错误消息“错误:列WK的长度必须为10(行数)或1,而不是0”。

预期输出为:

enter image description here

0 个答案:

没有答案