Can anyone please suggest how to mutate a new column based on dataset name? Below is my code:
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()))
The expected output is to have the name of dataset in object of WK. I run the code and get the error "Error: Column WK
must be length 10 (the number of rows) or one, not 0".
Expected output is: