R melt function

Here, we demonstrate the use of the melt() function in R. It produces long-format data in which the rows are unique variable-value combinations:

    >sample4=head(flights.sample,4)[c('year','month','dep_delay','arr_delay')]
    > sample4
    year month dep_delayarr_delay
    155501 2013     3         2         5
    2410   2013     1         0         4
    64158  2013    11        -7       -27
    221447 2013     5        -5       -12
    
    >melt(sample4,id=c('year','month'))
    year month  variable value
    1 2013     3 dep_delay     2
    2 2013     1 dep_delay     0
    3 2013    11 dep_delay    -7
    4 2013     5 dep_delay    -5
    5 2013     3 arr_delay     5
    6 2013     1 arr_delay     4
    7 2013    11 arr_delay   -27
    8 2013     5 arr_delay   -12
    >  
For more information, you can refer to the following link: http://www.statmethods.net/management/reshape.html.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset