Transforming daily data in wide format to long

Hi,

Can you please take couple of rows in your dataset and convert them into reprex?

Second, take a look at readxl package. Since you have composite headers (each month is one header and then each variable is another), you first need to read it in properly so that it will make it easier to work with.

Once this is done, converting your initial table to the format you want is straightforward. It'll be a combination of gather, separate and spread from tidyr package.

Very similar example from that package with solution is available as a demo here - https://github.com/tidyverse/tidyr/blob/master/demo/so-9684671.R.

1 Like