0

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!

Katmeus
  • 1
  • 1
  • [Reshape data from wide to long format](http://stackoverflow.com/questions/1181060), then split `dplyr:separate()` for the first column. – zx8754 Jul 20 '16 at 08:00
  • Dear Akrun, thnaks for the link. The melt function is great. However, I don't want to line up the column values after each other but the values of the row. To give an easy example: a<-c(1:3) b<-c(4:6) dfc<-cbind(a,b) The result I want to have is: 1 4 2 5 3 6 in a single column. Thanks! – Katmeus Jul 21 '16 at 13:02

0 Answers0