r - How to Apply llply() or lapply() to component of list produced by llply() or lapply() -


i'm using cl_tabulate stats on sample kdd cup 2009 data. here's sample portion of df.trainbase, data i'm working with...

    > sample <- df.trainbase[4100:4110,220:223]     > sample       var220  var221  var222     var223       4100 qceoi0_    oslk fxlavgi lm8l689qop       4101 otg4k41    oslk n9whlt9 lm8l689qop       4102 54petck    oslk eefa_vf lm8l689qop       4103 m_dam23    oslk nfzwudg lm8l689qop       4104 roeiplp    zckv k2sqeo9 lm8l689qop       4105 4uxglow    oslk catzs2d lm8l689qop       4106 rdm6pd1    oslk q53rkup lm8l689qop       4107 xqwylw4    oslk smve4qn lm8l689qop       4108 encovqc    oslk 8agqqms lm8l689qop       4109 b0v7gqp d0eeeji 80xxg6w lm8l689qop       4110 3abfc8e    oslk axcoera lm8l689qop      > tabs <- llply(sample,cl_tabulate) 

the tabs list looks (2 list elements shown):

    > tabs       $var220        values counts     1  qceoi0_      1     2  otg4k41      1     3  54petck      1     4  m_dam23      1     5  roeiplp      1     6  4uxglow      1     7  rdm6pd1      1     8  xqwylw4      1     9  encovqc      1     10 b0v7gqp      1     11 3abfc8e      1      $var221      values counts     1    oslk      9     2    zckv      1     3 d0eeeji      1 

i can number of prevalent level value specified list element (i.e., data column) this:

    > max(tabs[[1]]$counts)        [1] 37216 

but how max(tabs[[i]]$counts) i (e.g., using llply() if possible)? need value of prevalent level , how many times occurs each column:

ideally final result simple row per variable, variable name, prevalent factor value, , occurrences--for var196 example:

    var196   1k8t    49550 

is possible hand nested list (such 'tabs', above) llply() , point element 'below' column level of structure? don't see it.

...and solution (below) use melt()

    > m = melt(tabs, id="values")     > m <- m[-2]     > m      values value     l1     1     qceoi0_     1 var220     2     otg4k41     1 var220     3     54petck     1 var220     4     m_dam23     1 var220     5     roeiplp     1 var220     6     4uxglow     1 var220     7     rdm6pd1     1 var220     8     xqwylw4     1 var220     9     encovqc     1 var220     10    b0v7gqp     1 var220     11    3abfc8e     1 var220     12       oslk     9 var221     13       zckv     1 var221     ... 

which needed.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -