I'm trying to reshape the below data frame into a long format, but I'm not having much luck writing the code using reshape() or melt().
pH SO4
Lake Lat Long 1976 1977 1978 1981 1976 1977
1 58 7.2 4.59 -9999 4.48 4.63 6.5- -9999
2 58.1 6.3 4.97 -9999 4.6 4.96 5.5- -9999
4 58.5 7.9 4.32 4.23 4.4 4.49 4.8 6.5
5 58.6 8.9 4.97 4.74 4.98 5.21 7.4 7.6
I need to create a data frame where each row defines a unique combination of lake and year, columns for each chemical variable, and an additional column with the year of the measurement.