Mary Nastase
Mary Nastase

Reputation: 121

Make a new variabile in a group by function in shiny

I have some issues when I try to do this function:

server = function(input, output) {
Casco_l = subset(Data,INSR_TYPE==3003)
aggregated <- reactive({
Casco_l %>%
  group_by_("3003"=input$select) %>%
  summarise("Exposure" = sum(Exposure), "Earned Premium" = sum(Earned_Premium), ,"GWP" = sum(GWP_RON), "Incurred" = sum(inc),"NO of events" = sum(No_ev),
            "Frequency" = (sum(Exposure)/sum(No_ev)), "Loss Ratio" = (sum(Earned_Premium)/sum(inc)),
            "ULR"= ((sum(Earned_Premium)/sum(inc))*ulr), "Avr premium" = (sum(Earned_Premium)/sum(Exposure)),
            "Avr claim" = (ifelse(sum(No_ev)=0,0,(sum(inc)/sum(No_ev))) ))

})

Error:

 Error: unexpected '=' in:
 "                "ULR"= ((sum(Earned_Premium)/sum(inc))*ulr), "Avr premium" = (sum(Earned_Premium)/sum(Exposure)),
                  "Avr claim" = (ifelse(sum(No_ev)="

I don't understand why for "Loss Ratio" there is no problem and for the others variables smth doesn't work.

Thank you.

Upvotes: 0

Views: 30

Answers (1)

Just Burfi
Just Burfi

Reputation: 159

Reading your Error message:

Error: unexpected '=' in:
 "                "ULR"= ((sum(Earned_Premium)/sum(inc))*ulr), "Avr premium" = (sum(Earned_Premium)/sum(Exposure)),
                  "Avr claim" = (ifelse(sum(No_ev)="

The problem is that you should use "==" instead of "=" in the ifelse statement, that's why the script throws an error.

Upvotes: 1

Related Questions