I have several problems reshaping my data frame. The data frame consists of merged information on gauging station, year, month and day in the first column and measured data in hourly resolution is placed in column 2 to 24.
STN_YYMMDD 00:00 01:00 02:00 03:00 04:00 05:00 06:00
101_760101 0 0 0 0 0 0 0
101_760102 1 1 1 1 1 1 1
101_760103 3 13 5 3 0 5 5
101_760104 8 15 18 15 36 5 5
101_760105 0 0 0 0 0 15 NA00
102_760101 0 0 0 0 0 0 0
On top of that data from different stations covering different time periods are in the same data frame (but different rows). What I actually what to have is a) a single file for each station b) consisting of 6 columns (STN, YY, MM, DD, hh, value. See example below:
STN YY MM DD HH value
101 76 1 1 00:00 0
101 76 1 1 01:00 0
101 76 1 1 02:00 0
101 76 1 1 03:00 0
101 76 1 1 04:00 0
101 76 1 1 05:00 0
101 76 1 1 06:00 0
I know how to extract the STN, YY, MM, DD information in the file and how to subset the file subsequently by naming individual stations. But since my data frame consist of several hundred stations I cannot address them all individually and I am searching for a loop produce to subset the file by station automatically. Further, I struggle to bind the values of each row after each other and transpose them to a column. I suppose this should be easy but somehow I cannot find the right way to do it. I tried matrix, stack and reshape with no success. Thanks for your support!