http://stackoverflow.com/questions/15237995/combining-variables-together-into-a-list


@RicardoSaporta edit: 

You can skip the reshape step, if youd like, using `list(list(c(....)))`  
This will probably save a fair bit of execution time. 

  
    DT <- data.table(DT)
    DT[,   Fruit := list(list(c(  Fruit.1,   Fruit.2,   Fruit.3))), by=BuyerID]
    DT[, Ammount := list(list(c(Amount.1, Amount.2, Amount.3))), by=BuyerID]

    # Or as a single line
    DT[,   list(  Fruit = list(c( Fruit.1,  Fruit.2,  Fruit.3)), 
                Ammount = list(c(Amount.1, Amount.2, Amount.3)), 
                Total = sum(Amount.1, Amount.2, Amount.3), 
                Count),  # other columns used
                by = BuyerID]



    DT <- DT <- data.frame(
      BuyerID = c(879,765,123,11,773), 
      Fruit.1 = c('Banana','Strawberry','Orange','Strawberry','Kiwi'),
      Fruit.2 = c('Apple','Apple','Banana',NA,'Banana'),
      Fruit.3 = c( NA, 'Orange',NA,NA,NA),
      Amount.1 = c(4,1,1,3,1), Amount.2 = c(3,2,1,NA,2), Amount.3 = c(NA,4,1,NA,NA),
      Total = c(7,7,3,3,3), 
      Count = c(2,3,2,1,2), 
      stringsAsFactors = FALSE)

DT <- data.table(DT

    DT <- DT <- data.frame(
      BuyerID = c(879,765,123,11,773), 
      Fruit.1 = c('Banana','Strawberry','Orange','Strawberry','Kiwi'),
      Fruit.2 = c('Apple','Apple','Banana',NA,'Banana'),
      Fruit.3 = c( NA, 'Orange',NA,NA,NA),
      Amount.1 = c(4,1,1,3,1), Amount.2 = c(3,2,1,NA,2), Amount.3 = c(NA,4,1,NA,NA),
      stringsAsFactors = FALSE)
