0

I know this is super simple, but I always have trouble with this.

site     diagnosis    week   value
Site A   anxiety      total  13
Site B   anxiety      total  1
Site A   depression   total  27
Site C   depression   total  18

I want to get the data in a state where I can plot it by diagnosis. I don't care about site or week, just want the sum of all values for each diagnosis.

I have tried

df %>% 
  group_by(diagnosis) %>% 
  summarize(
    total = sum(value, na.rm = TRUE))

But I get the error

"Error in summarize():
! Problem while computing total_value = sum(n, na.rm = TRUE).
ℹ The error occurred in group 1: diagnosis = "anxiety".
Caused by error in sum():
! invalid 'type' (closure) of argument
Run rlang::last_error() to see where the error occurred."

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Jackie
  • 43
  • 4
  • 1
    Check that you are actually using `dplyr::summarize`. Your code works correctly on my machine. Or check that `value` is numeric, and not a character column – Maël Mar 05 '23 at 16:43
  • It was a character, thank you! – Jackie Mar 05 '23 at 17:20

0 Answers0