Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can also get the output you're looking for if you <code>unlist</code> the <code>list</code> column first and make it so you have a long <code>data.frame</code> to start with:</p> <pre><code>visits &lt;- unlist(df$visits, use.names=FALSE) df &lt;- df[rep(rownames(df), sapply(df$visits, length)), c("bee.num", "plant")] df$visits &lt;- visits aggregate.data.frame(df$visits, by=list(bee.num = df$bee.num, plant = df$plant), FUN=c) # bee.num plant x # 1 1 d 1, 2, 3, 4, 5, 6, 7, 8, 9 # 2 2 d 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 # 3 3 d 5, 6, 7, 8, 9, 10, 11 # 4 1 w 10, 11 # 5 3 w 1, 2, 3, 4 ## Or, better yet: aggregate(visits ~ bee.num + plant, df, c) </code></pre> <p>By the way, "data.table" can handle this listing and unlisting pretty directly:</p> <pre><code>library(data.table) DT &lt;- data.table(df) setkey(DT, bee.num, plant) DT[, list(visits = list(unlist(visits))), by = key(DT)] # bee.num plant visits # 1: 1 d 1,2,3,4,5,6, # 2: 1 w 10,11 # 3: 2 d 1,2,3,4,5,6, # 4: 3 d 5,6,7,8,9,10, # 5: 3 w 1,2,3,4 </code></pre> <p>The output there only <em>looks</em> truncated. All the information is there:</p> <pre><code>str(.Last.value) # Classes ‘data.table’ and 'data.frame': 5 obs. of 3 variables: # $ bee.num: num 1 1 2 3 3 # $ plant : Factor w/ 2 levels "d","w": 1 2 1 1 2 # $ visits :List of 5 # ..$ : int 1 2 3 4 5 6 7 8 9 # ..$ : int 10 11 # ..$ : int 1 2 3 4 5 6 7 8 9 10 ... # ..$ : int 5 6 7 8 9 10 11 # ..$ : int 1 2 3 4 # - attr(*, "sorted")= chr "bee.num" "plant" # - attr(*, ".internal.selfref")=&lt;externalptr&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload