0

So i currently have a data frame in the format of:

Product  Jan   Feb    Mar   Apr
Fish     0.5   0.2    0.3   0.7
Veg      0.3   0.1    0.8   0.5
Beef     0.8   0.9    0.4   0.6

and what I'm trying to do now is to reformat the data frame so that i would obtain:

Product    Month    Sell_rate
Fish        Jan        0.5
Fish        Feb        0.2
Fish        Mar        0.3
Fish        Apr        0.7
Veg         Jan        0.3
Veg         Feb        0.1
Veg         Mar        0.8
Veg         Apr        0.5
Beef        Jan        0.8
Beef        Feb        0.9
Beef        Mar        0.4
Beef        Apr        0.6

I tried implementing it by reshape:

new_df <- reshape(df, new_col = "Month", )

but i seemed to be doing it the wrong way. Could anyone help me out on this. Much appreciated

Maxxx
  • 3,688
  • 6
  • 28
  • 55
  • `tidyr::gather(df, Month, sell_rate, -Product)` – Ronak Shah Apr 18 '19 at 07:13
  • @RonakShah the dataframe is going to be in the sequence of FishVegBeef, instead of FishFishFishVegVegVegBeefBeefBeef in the products column. – Maxxx Apr 18 '19 at 07:43
  • you can just `arrange` it ,right? `tidyr::gather(df, Month, sell_rate, -Product) %>% arrange(Product)` ? Is the sequence important to? – Ronak Shah Apr 18 '19 at 07:49

0 Answers0