0

I created a dataframe with names

[1] "promotion"  "code"       "01.09.2016" "01.16.2016" "01.23.2016" "01.30.2016" "02.06.2016" "02.13.2016" "02.20.2016" "02.27.2016" "03.05.2016"
[12] "03.12.2016" "03.19.2016" "03.26.2016" "04.02.2016" "04.09.2016" "04.16.2016" "04.23.2016" "04.30.2016" "05.07.2016" "05.14.2016" "05.21.2016"
[23] "05.28.2016" "06.04.2016" "06.11.2016" "06.18.2016" "06.25.2016" "07.02.2016" "07.09.2016" "07.16.2016" "07.23.2016" "07.30.2016" "08.06.2016"
[34] "08.13.2016" "08.20.2016" "08.27.2016" "09.03.2016" "09.10.2016" "09.17.2016" "09.24.2016" "10.01.2016" "10.08.2016" "10.15.2016" "10.22.2016"
[45] "10.29.2016" "11.05.2016" "11.12.2016" "11.19.2016" "11.26.2016" "12.03.2016" "12.10.2016" "12.17.2016" "12.24.2016" "12.31.2016"

I used this code

melt(Scanning_Cost, names(Scanning_Cost)[1:2])

this error shows

Error in match.names(clabs, names(xi)) : 
  names do not match previous names

I want my date columns to come in front of the products and show the count

promotion   code `01.09.2016` `01.16.2016` `01.23.2016` `01.30.2016` `02.06.2016` `02.13.2016` `02.20.2016` `02.27.2016`
                              <chr>  <chr>        <lgl>        <lgl>        <lgl>        <lgl>        <dbl>        <dbl>        <dbl>        <dbl>
1   D - MA BEACH WAVES MOUSSE 8.5OZ 372548           NA           NA           NA           NA            1            1            1            1
2 M/A 100% COCONUT OIL JAR     10OZ 968701           NA           NA           NA           NA            1            1            1            1
3 M/A BYE FRIZZ 30DAY KRTN SMT3.38Z 178685           NA           NA           NA           NA            1            1            1            1
4 M/A BYE GRY TMP SPRY L/M BRN1.5OZ 373984           NA           NA           NA           NA            1            1            1            1
5 M/A BYE GRY TMP SPRY M/D B/B1.5OZ 373985           NA           NA           NA           NA            1            1            1            1
6 M/A COCO CREAM CRL CD       8.4OZ 968704           NA           NA           NA           NA            1            1            1            1
shailesh
  • 43
  • 1
  • 7
  • 2
    Please provide a reproducible example! https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – FAMG Oct 31 '17 at 15:20
  • 1
    Looks like your data is a `tibble`, I think it should work if you use `melt(as.data.frame(Scanning_Cost), names(Scanning_Cost)[1:2])`. – Mike H. Oct 31 '17 at 15:24
  • @MikeH. you're right. That said, the second answer to that question is the answer to this question. – Eumenedies Oct 31 '17 at 15:29
  • Yes. This worked! Thanks guys. My amateurity has let me down again, only to be saved by the knights of Stack Overflow. – shailesh Oct 31 '17 at 15:31
  • 1
    @MikeH.: That's it. I had my "data frame" created by `dplyr`'s `select`and it was a tibble. Not easy to spot the problem. Thanks! – Peter May 05 '20 at 16:08

0 Answers0