0

Original data frame in R df_orginal

AB    CD  EF  GH
A     0   12  M
A     0   13  F
A     0   14  F
A     1   16  M
A     1   17  F
A     1   18  M
A     1   18  M
A-2   0   78  M
A-2   0   12  M
A-2   0   12  F
A-2   1   12  F
A-2   1   47  M
A-2   1   34  F

Outputs I would like: df_1 = max, min, mean of EF based on AB The code I am attempting to use is:

df_1 <- df_original %>% group_by(AB, CD) 
df_1 <- summarise(EF, max, min, mean)

Error: Problem with summarize() input...1 x Input ...1 must be a vector, not a function Input ...1 is max

AB  CD  Max  Min  Mean 
A   0   14   12   13
A   1   18   16   17.25
A-2 0   78   12   34
A-2 1   47   12   31

And df_2 = total number of M or F from GH based on AB and CD

df_2 <- df_original %>% group_by(AB, CD, GH) 
df_2 <-  summarise(GH, sum) 

And I am having trouble writing the rest of this code

AB  CD  M_total  F_total
A   0   1        2
A   1   3        1
A-2 0   2        1
A-2 1   1        2
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
vcat
  • 263
  • 1
  • 9
  • Pivoting is not what you need: that technique preserves all data, it does not summarize. In the link I'm marking this a dupe of, there are several answers that suggest (for example) `dplyr`'s `summarize` function; simply calculate multiple columns (instead of "just mean" as they tend to show there). – r2evans Apr 06 '21 at 12:39
  • (While you do mention trying `summarize`, what you ask for is perfectly addressed in that link. If you still do not get it to work, then (1) [edit] the question, and show your code and errors, it does nothing for us for you to say *"only getting error messages"*, we need to see the **code** and the literal **errors**; (2) ping me to reopen the question. Good luck!) – r2evans Apr 06 '21 at 12:41

0 Answers0