1

New to R. Using dplyr, trying to group_by multiple variables, summarize by multiple variables, multiple functions.

This works as expected

mtcars %>% 
+     group_by(cyl,hp) %>% 
+     summarise(min_mpg = min(mpg) , min_disp = min(disp), max_mpg = max(mpg) , max_disp = max(disp))

But when I try to replicate with my df

vmp %>% 
    +     group_by(Priority,LOS) %>% 
    +     summarise(inv_total = sum(Inv_Total), sr_count = count(SR_Nmbr))

I receive this error:

Error in summarise_impl(.data, dots) : Evaluation error: no applicable method for 'groups' applied to an object of class "factor".

What am I doing wrong? Thx

2 Answers 2

1
library(dplyr)
vmp %>%
     mutate(Inv_Total=as.numeric(as.character(Inv_Total))) %>% 
     group_by(Priority,LOS) %>%
     summarise(sr_count=n(), 
               inv_total=sum(Inv_Total))
Sign up to request clarification or add additional context in comments.

Comments

0

We can use type.convert to convert the column types automatically

vmp %>%
    mutate_all(funs(type.convert(as.character(.), as.is = TRUE))) %>%
    group_by(Priority, LOS) %>%
    summarise(inv_total = sum(Inv_Total), sr_count =n())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.