2

this is my code:

lcdf %>%
  group_by(purpose) %>%
  summarise(
    nLoans=n(),
    defaults=sum(loan_status=="Charged Off"),
    avgInterest= mean(int_rate),
    avgLoanAMt=mean(loan_amnt)
  )

I get this error:

Error: `n()` must only be used inside dplyr verbs.

What do I do? Thanks!

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • Can you show `dput(lcdf)`. Your syntax seems correct? Try this on a fresh R session with only `library(dplyr)` loaded – akrun Feb 25 '21 at 18:05
  • 2
    Restart R, then either (1) don't load `plyr`, or (2) load `dplyr` *second*. To confirm, type in just `summarise`, and I'm going to guess that the output ends with `` (which does *not* know what to do with `n()`. It should end with ``. – r2evans Feb 25 '21 at 18:09

0 Answers0