Group-by and finding largest samples

Hello everyone,

I am a new R user and was wondering how I would get a aggregated views of my data. I have found how to get distinct units (policies) (

)but would need some help in getting market leading firms (top 10). I need to incorporate an aggregation of the count of policies and find the firms with the largest market shares.

Thanks in advance.

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue?, screenshots are not very useful. Please have a look at this guide, to see how to create one:

1 Like

Hi,

Thanks for your reply.

Please find sample data below.

I would need some help in getting market leading firms (top 10). I need to incorporate an aggregation of the count of policies and find the firms with the largest market shares.

AUTOMOBILE_INSURANCE_NAME AUTOMOBILE_INSURANCE_POLICY_NUMBER
AMERICAN TRANSIT INSURANCE COMPANY B621762-3
ALLSTATE INSURANCE COMPANY 648859846
HEREFORD INSURANCE COMPANY CA287907-2
AMERICAN TRANSIT INSURANCE COMPANY B704781-2
AMERICAN TRANSIT INSURANCE COMPANY B621762-3
ALLSTATE INSURANCE COMPANY 648859846
HEREFORD INSURANCE COMPANY CA287907-2
AMERICAN TRANSIT INSURANCE COMPANY B704781-2
AMERICAN TRANSIT INSURANCE COMPANY B708637-2
CLEAR BLUE INSURANCE COMPANY AT01-003670
HEREFORD INSURANCE COMPANY CA295191-1
CLEAR BLUE INSURANCE COMPANY AT01-007575
CLEAR BLUE INSURANCE COMPANY AT01-003492
AMERICAN TRANSIT INSURANCE COMPANY B408385-5
AMERICAN TRANSIT INSURANCE COMPANY B806256-1
MAYA ASSURANCE COMPANY 1-MA024411
HEREFORD INSURANCE COMPANY CA275341-3
CLEAR BLUE INSURANCE COMPANY AT01-001547
HEREFORD INSURANCE COMPANY CA291340-1
AMERICAN TRANSIT INSURANCE COMPANY B602469-3
AMERICAN TRANSIT INSURANCE COMPANY FPT002982-2
HEREFORD INSURANCE COMPANY CA299404-1
AMERICAN TRANSIT INSURANCE COMPANY B621571-3
HEREFORD INSURANCE COMPANY CA299639-1
HEREFORD INSURANCE COMPANY CA300277-1
AMERICAN TRANSIT INSURANCE COMPANY B808716-1
AMERICAN TRANSIT INSURANCE COMPANY B615665-3
AMERICAN TRANSIT INSURANCE COMPANY B710886-2
CLEAR BLUE INSURANCE COMPANY AT01-007131
AMERICAN TRANSIT INSURANCE COMPANY FPT002855-2
AMERICAN TRANSIT INSURANCE COMPANY B801748-1
HEREFORD INSURANCE COMPANY CA281696-2
HEREFORD INSURANCE COMPANY CA286329-2
AMERICAN TRANSIT INSURANCE COMPANY B609160-3

That is not copy/paste friendly and you are not showing any code. Please read the guide on the link I gave you and try to make a proper reproducible example

Hi I have repasted the data as plain text.

Active_uber_policy_chk <- Active_uber_check %>%

  • group_by(AUTOMOBILE_INSURANCE_POLICY_NUMBER) %>%
    
  • summarise(count n_distinct = (AUTOMOBILE_INSURANCE_POLICY_NUMBER))
    

Error: unexpected symbol in:
" group_by(AUTOMOBILE_INSURANCE_POLICY_NUMBER) %>%
summarise(count n_distinct"

Active_uber_policy_chk

AUTOMOBILE_INSURANCE_NAME AUTOMOBILE_INSURANCE_POLICY_NUMBER
AMERICAN TRANSIT INSURANCE COMPANY B621762-3
ALLSTATE INSURANCE COMPANY 648859846
HEREFORD INSURANCE COMPANY CA287907-2
AMERICAN TRANSIT INSURANCE COMPANY B704781-2
AMERICAN TRANSIT INSURANCE COMPANY B621762-3
ALLSTATE INSURANCE COMPANY 648859846
HEREFORD INSURANCE COMPANY CA287907-2
AMERICAN TRANSIT INSURANCE COMPANY B704781-2
AMERICAN TRANSIT INSURANCE COMPANY B708637-2
CLEAR BLUE INSURANCE COMPANY AT01-003670
HEREFORD INSURANCE COMPANY CA295191-1
CLEAR BLUE INSURANCE COMPANY AT01-007575
CLEAR BLUE INSURANCE COMPANY AT01-003492
AMERICAN TRANSIT INSURANCE COMPANY B408385-5
AMERICAN TRANSIT INSURANCE COMPANY B806256-1
MAYA ASSURANCE COMPANY 1-MA024411
HEREFORD INSURANCE COMPANY CA275341-3
CLEAR BLUE INSURANCE COMPANY AT01-001547
HEREFORD INSURANCE COMPANY CA291340-1
AMERICAN TRANSIT INSURANCE COMPANY B602469-3
AMERICAN TRANSIT INSURANCE COMPANY FPT002982-2
HEREFORD INSURANCE COMPANY CA299404-1
AMERICAN TRANSIT INSURANCE COMPANY B621571-3
HEREFORD INSURANCE COMPANY CA299639-1
HEREFORD INSURANCE COMPANY CA300277-1
AMERICAN TRANSIT INSURANCE COMPANY B808716-1
AMERICAN TRANSIT INSURANCE COMPANY B615665-3
AMERICAN TRANSIT INSURANCE COMPANY B710886-2
CLEAR BLUE INSURANCE COMPANY AT01-007131
AMERICAN TRANSIT INSURANCE COMPANY FPT002855-2
AMERICAN TRANSIT INSURANCE COMPANY B801748-1
HEREFORD INSURANCE COMPANY CA281696-2
HEREFORD INSURANCE COMPANY CA286329-2
AMERICAN TRANSIT INSURANCE COMPANY B609160-3

As I said, plain text is not copy/paste friendly, please read the guide if you want to improve your chances of getting help. Also, please be aware that refusing to follow good practices on the forum can be interpreted as rude.

This post was flagged by the community and is temporarily hidden.

Hi! Could you try creating a reprex as mentioned earlier. It will not only go along way helping but might be very helpful to someone experiencing a similar problem. Check this out how to create one