reshape2 - Convert from long wide data fromat to long data format in R with multiple depth headers -


maybe can't done because have data in bad format, i'm trying "kind of" wide format long format. if modify data in excel first, know how melt, have lot of data, , i'm hoping not have modify hand first.

basically have headers have depth have multiple descriptors each column of sales. account, brand, variety , tier (and maybe others depending on how goes)

            account             brand             variety             tier dates    1/1/2011    sales xxx 2/1/2011    sales xxx 

and format need in be

date account brand variety tier sales 

i don't understand how convert using reshape or melt though. suggestions, or have hand?

edit

actual data looks (names changed protect innocent)

account   account account   account   account   account b brand     brand   brand         brand b         brand b         brand c variety   cab           chard           merlot          pinot grigio    pinot noir  tier     tier 2    tier 3          tier 2          tier 1          tier 3 date                     6/1/20     35            47              35               28               -    7/1/2011   12            17              12               12              84                8/1/2011   -             -               -                -                -    9/1/2011   7             7           7            7               84  10/1/2011 28             28              28              28              112  11/1/2011                                            168  12/1/2011  7             7           7            7              224  1/1/2012                 14                              236  

if massage in excel this

    date    compilation_red compilation_white   oak_cab oak_chard 1   11/1/2012   351 140 183 190 2   12/1/2012   191 99  120 92 3   1/1/2013    96  56  87  51 4   2/1/2013    30  30  84  61 5   3/1/2013    96  70  100 57 6   4/1/2013    60  38  52  22 7   5/1/2013    12  17  65  49 8   6/1/2013    9   7   28  21 9   7/1/2013    16  13  23  22 10  8/1/2013    26  29  40  33 11  9/1/2013    14  4   30  23 12  10/1/2013   17  4   47  31 13  11/1/2013   23  5   63  35 14  12/1/2013   25  3   70  41 15  1/1/2014    44  1   88  41 16  2/1/2014    28  7   57  43 

then know how use melt long format

myitem=melt(account, id.vars="date", variable.name="variety", value.name="sales") 

i don't understand how deal headers, , them long format.

also, don't understand why table looks fine when put in, mashed in preview.


Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -