Hi,
I'm trying to convert to my wide dataset into a long form dataset.
First I had the data set below:
Date Temp X1 X2 X3 X4 X5
1 2018-01-01 00:00:00 8.0 0.6472976 0.5178381 0.5609912 0.7336039 0.8199103
2 2018-01-01 01:00:00 7.9 0.6806634 0.5445307 0.5899083 0.7714185 0.8621737
3 2018-01-01 02:00:00 7.8 0.7140293 0.5712234 0.6188254 0.8092332 0.9044371
4 2018-01-01 03:00:00 7.7 0.8208000 0.6566400 0.7113600 0.9302400 1.0396800
5 2018-01-01 04:00:00 7.3 1.1110829 0.8888664 0.9629386 1.2592273 1.4073717
With the following code I was able to achieve the right format:
data2 = gather(data, house, consumption, -Date, -Temp)
Date Temp house consumption
1 2018-01-01 00:00:00 8.0 X1 0.6472976
2 2018-01-01 01:00:00 7.9 X1 0.6806634
3 2018-01-01 02:00:00 7.8 X1 0.7140293
4 2018-01-01 03:00:00 7.7 X1 0.8208000
5 2018-01-01 04:00:00 7.3 X1 1.1110829
However, currently I not only have consumption as a variable but two other variables as well (Elabel and Hsize). These two variables are static for each house (every house has a certain Elabel and Hsize). My dataset now looks like this:
Date Temp X1 Elabel1 Hsize1 X2 Elabel2 Hsize2 X3 Elabel3 Hsize3 X4 Elabel4 Hsize4 X5 Elabel5 Hsize5 X6
1 2018-01-01 00:00:00 8.0 0.8093377 A 100 0.9413433 C 90 0.8801952 E 75 0.8984059 A 60 0.7658825 B 120 0.7069353
2 2018-01-01 01:00:00 7.9 0.9300447 A 100 1.1047173 C 90 0.8668304 E 75 0.7173619 A 60 0.8714931 B 120 0.7565921
3 2018-01-01 02:00:00 7.8 0.8468523 A 100 0.9813693 C 90 0.9104481 E 75 0.9178342 A 60 0.8925958 B 120 0.6474878
4 2018-01-01 03:00:00 7.7 1.0558602 A 100 1.3127769 C 90 1.1186276 E 75 1.0786968 A 60 0.9416125 B 120 0.8699044
5 2018-01-01 04:00:00 7.3 1.2765728 A 100 1.6924849 C 90 1.4120881 E 75 1.2462317 A 60 1.1781826 B 120 1.1912390
I'm trying to convert this to long format. Below is an example of how I would like it to look, but I can't seem to achieve this. Would any of you be able to help me?
Date Temp house Elabel Hsize consumption
1 2018-01-01 00:00:00 8.0 X1 A 100 0.6472976
2 2018-01-01 01:00:00 7.9 X1 A 100 0.6806634
3 2018-01-01 02:00:00 7.8 X1 A 100 0.7140293
4 2018-01-01 03:00:00 7.7 X1 A 100 0.8208000
5 2018-01-01 04:00:00 7.3 X1 A 100 1.1110829