0

Could somebody give me an adviсe how should I handle the data set to take the average value for the dates that have multiple values, please.

I.e., from this data set:

df <- data.frame(Date = c("2014-01-05", "2014-01-05", "2014-01-08", "2014-01-11", 
                  "2014-01-11", "2014-01-11", "2014-01-17"), 
         Value = c(0.210, 0.220, 0.466, 0.760, 0.815, 0.889, 0.400))

I need to take this one:

df1 <- data.frame(Date = c("2014-01-05", "2014-01-08", "2014-01-11", "2014-01-17"), 
         Value = c(0.215, 0.466, 0.821, 0.400))

Many thanks in advance!

NatalyR
  • 1
  • 2
  • 1
    Try with `aggregate(Value~Date, df, mean)` or `library(dplyr); df %>% group_by(Date) %>% summarise(Value = mean(Value))` or `library(data.table); setDT(df)[, .(Value = mean(Value)), Date]` – akrun Feb 14 '17 at 12:46
  • 1
    Thank you very much @akrun! – NatalyR Feb 14 '17 at 12:52

0 Answers0