0

I am having some problems with summarizing a table that I have grouped by Date. Here is the data:

df <- structure(list(Gerät = c("=Soll_149", "=Soll_149", "=Soll_149", 
"=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", 
"=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", 
"=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", 
"=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", 
"=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", "=Soll_149", 
"=Soll_149", "=Soll_149"), Datum = structure(c(18324, 18324, 
18324, 18324, 18324, 18324, 18324, 18324, 18324, 18324, 18324, 
18324, 18324, 18324, 18325, 18325, 18325, 18325, 18325, 18325, 
18325, 18325, 18325, 18325, 18325, 18325, 18325, 18325, 18325, 
18325), class = "Date"), Uhrzeit = c("10:00:00", "11:00:00", 
"12:00:00", "13:00:00", "14:00:00", "15:00:00", "16:00:00", "17:00:00", 
"18:00:00", "19:00:00", "20:00:00", "21:00:00", "22:00:00", "23:00:00", 
"0:00:00", "1:00:00", "2:00:00", "3:00:00", "4:00:00", "5:00:00", 
"6:00:00", "7:00:00", "8:00:00", "9:00:00", "10:00:00", "11:00:00", 
"12:00:00", "13:00:00", "14:00:00", "15:00:00"), Tiefe = c("1.28", 
"1.28", "1.28", "1.28", "1.28", "1.28", "1.28", "1.28", "1.28", 
"1.28", "1.28", "1.28", "1.28", "1.28", "1.28", "1.28", "1.28", 
"1.28", "1.28", "1.28", "1.28", "1.28", "1.28", "1.28", "1.28", 
"1.28", "1.28", "1.28", "1.28", "1.28"), Temperatur = c("3.9", 
"4.5", "5.3", "6.3", "6.4", "7", "6.5", "6", "5.6", "5.3", "4.9", 
"4.5", "4.1", "4", "3.7", "3.3", "3", "2.6", "2.3", "2", "1.8", 
"1.6", "1.8", "2.7", "4.4", "5.1", "6", "7.2", "8.1", "7.8"), 
    Spannung = c("8.63", "8.6", "8.58", "8.57", "8.53", "8.53", 
    "8.5", "8.48", "8.46", "8.44", "8.43", "8.43", "8.41", "8.41", 
    "8.39", "8.39", "8.37", "8.37", "8.36", "8.36", "8.36", "8.36", 
    "8.36", "8.37", "8.41", "8.41", "8.43", "8.44", "8.44", "8.43"
    ), X = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA)), row.names = c(NA, -30L), class = "data.frame")

Here is the code, I have been using so far.

df %>% mutate(Tiefe = as.numeric(Tiefe),
              Temperatur= as.numeric(Temperatur)) %>%
              group_by(Datum) %>%
              summarize(Tiefe = mean(Tiefe))

However, I get the output

Tiefe
1  1.28

What is going on here? I would like to have 2 values for "Tiefe", for the 2020-03-03 as well as 2020-03-04. What am I missing. My original dataset has more than 400 distinct dates, but when I summarize I just get that one value as above. Also, I would like to preserve the "date" column in the output, so it should be like

date           Tiefe

"2020-03-03"    1.28
"2020-03-04"      x
"2020-03-05"      y

and so forth. I could have sworn I have done this before, but I am stuck now and dont know what to do. Any help is really appreciated! :) Thanks a lot in advance.

Cheers

Effigy
  • 145
  • 7
  • 3
    YOu may need `dplyr::summarise` as `plyr::summarise` might be masking – akrun Apr 26 '21 at 16:19
  • 1
    I agree with akrun. Running your code is fine. Just run `summarise` (without parenthesis) in the console to see from which package it is loaded. If it is not `dplyr` then your problem lies there. – Dan Chaltiel Apr 27 '21 at 09:22
  • Oh yes, it worked, thanks a lot! – Effigy Apr 29 '21 at 09:58

0 Answers0