I have a big dataframe\matrix with dates in column and the hours in the rows. How can I rewrite the data in a dataframe with the time series in date and hour in a column and its respective recorder in another one ?
            Asked
            
        
        
            Active
            
        
            Viewed 59 times
        
    -2
            
            
        - 
                    3When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions – MrFlick Mar 06 '18 at 21:21
1 Answers
0
            In the case that your data is like this and has name df
hour    2018-03-01  2018-03-02  2018-03-03
06:00   abc             def         ghj
07:00   klm             nop         qwe
08:00   rty             hjk         mnb
09:00   klp             ghm         asd
you can use melt from reshape2 library.
install.packages(reshape2)
library(reshape2)
reshape2::melt(df, id.vars = "hour")
which will give this (no matter that your receptive recorder is numeric or character)
hour   variable   value
06:00 2018-03-01   abc
07:00 2018-03-01   klm
08:00 2018-03-01   rty
09:00 2018-03-01   klp
06:00 2018-03-02   def
07:00 2018-03-02   nop
08:00 2018-03-02   hjk
09:00 2018-03-02   ghm
06:00 2018-03-03   ghj
07:00 2018-03-03   qwe
08:00 2018-03-03   mnb
09:00 2018-03-03   asd
 
    
    
        Selcuk Akbas
        
- 711
- 1
- 8
- 20
 
    