1

I do have a list of 53 data frames (purchase01 to purchase53), ordered by date, with 18 variables and distinct number of rows (tryed, but coulden't paste a example on the following). I want to aggregate each distinct data frame by its repeated values of "V9"- factor- by sum the column "V2"- numeric. I coulden't find the answer yet.

For only one dataframe I can use aggregate.data.frame(purchase00$V12, by = list(purchase00($V9),FUN = sum) and itjust works fine.

I tryed llply, llply(.data = purchase, .fun = aggregate.data.frame, by= list(unique((V9),sum, .inform = TRUE)

but without sucess, it seems that the function does not receive the by for every dataframe nor the function sum. Also the mapply didn't work well for me.

Jaap
  • 77,147
  • 31
  • 174
  • 185
Guil Botler
  • 33
  • 1
  • 5

1 Answers1

4
## assuming your list is called list_of_df
require(dplyr)

summarized_list <- lapply(list_of_df,  function(x) {

x %>% group_by(V9) %>% summarize(sum(V2))

})

This will return a list with the summary of each data frame in your purchase list.

If you don't want to use dplyr , you can do this with base :

lapply(list_of_df, function(x) {aggregate(values ~ day_of_week, data = x, sum) })
vagabond
  • 3,288
  • 4
  • 40
  • 74
  • the dplyr gavte me a sumaraized data, in the case I needed the output without sommirize it. The lapply just worked fine. Thank you – Guil Botler Nov 13 '16 at 09:12