tidyr::gather()
for whatever reason is saving the original rows of a wide dataset I am attempting to transform to long and then placing the long data below those rows. This is being applied to a dataframe read in from a csv.
my original data is setup like this but with 30+ columns for different gas species:
X Date Treatment Carbon.dioxide.CO2_mean Methane.CH4_mean ...
1 10/2/2018 1A01 14886.2 2.194333 ...
2 10/2/2018 1A27 352313.8 18.034400 ...
3 10/2/2018 1A35 112027.4 7.994200 ...
4 10/2/2018 1A60 181449.2 5.270500 ...
...
This my code:
long.mean.myfiles.subset <- removed.mean.myfiles.subset %>%
gather(Gas_Species, Gas_Concentration_PPM, -c(Date, Treatment))
This is the output I expect:
# Date Treatment Gas_Species Gas_Concentration_PPM
#1 10/2/2018 1A01 Carbon.dioxide.CO2_mean 1.488620e+04
#2 10/2/2018 1A27 Carbon.dioxide.CO2_mean 3.523138e+05
#3 10/2/2018 1A35 Carbon.dioxide.CO2_mean 1.120274e+05
This what I'm getting:
Date Treatment Gas_Species Gas_Concentration_PPM
1 10/2/2018 1A01 X 1.000000e+00
2 10/2/2018 1A27 X 2.000000e+00
3 10/2/2018 1A35 X 3.000000e+00
4 10/2/2018 1A60 X 4.000000e+00
5 9/12/2018 1A01 X 5.000000e+00
6 9/12/2018 1A27 X 6.000000e+00
...
25 10/2/2018 1A01 Carbon.dioxide.CO2_mean 1.488620e+04
26 10/2/2018 1A27 Carbon.dioxide.CO2_mean 3.523138e+05
27 10/2/2018 1A35 Carbon.dioxide.CO2_mean 1.120274e+05
28 10/2/2018 1A60 Carbon.dioxide.CO2_mean 1.814492e+05
The original wide dataset has 24 rows not including the labels and roughly 40 columns (one for each gas species) and associated Date and Treatment. I wanted just the date and treatment then to create gas_species and concentration columns.
There are NA values I want to retain.
I was able to generate the correct output originally with this code before this issue occurred. I have wiped the GE, any RData, and RHistory. I restarted R and attempted again with no success. I can't seem to find any documentation of this issue elsewhere and was wondering if anyone knows why this is happening an how to fix it?