Assignment 4 Section "e"

Assignment 4 Section "e"

by Edgardo Torres -
Number of replies: 11

Anyone willing to help/hint the answer to section "e" of assignment 4?

Using the table() function complicates the assignment a lot. Any workarounds?

I have managed to make a table with the frequencies within it, I simply can't extracting the information from the table because its not a data.frame.

Would greatly appreciate any help.

In reply to Edgardo Torres

Re: Assignment 4 Section "e"

by Liane Phung -
I managed to get the table into a data frame by storing the table() function itself within the data.frame
ie. Sep.wards <- data.frame(table(n.Sep$spreadsheet.Ward))
(I had my slicing for Sep date in n.Sep)

However, when I sort by Freq from the table for the ward with most 311 calls, I am getting "Beaches-East York (32)" as the most instead of "Trinity-Spadina (20)". Wondering if anyone else is getting this answer?
In reply to Liane Phung

Re: Assignment 4 Section "e"

by Erik Spence -
If you sort the table then things should be quite easy. You don't need to recast the table into a data frame.
In reply to Liane Phung

Re: Assignment 4 Section "e"

by Edgardo Torres -
Im getting Etobicoke-Lakeshore, this is my sorted table:

Etobicoke-Lakeshore       Beaches-East York        Toronto-Danforth 

                  15835                   15232                   14282 

      Eglinton-Lawrence         Trinity-Spadina      Parkdale-High Park 

                  14262                   14174                   13521 

             Willowdale              St. Paul's               Davenport 

                  12630                   12413                   12309 

  Scarborough Southwest        Scarborough East        Etobicoke Centre 

                  12260                   12213                   11537 

        Don Valley West      Scarborough Centre       York South-Weston 

                  11053                   11024                   10782 

Toronto Centre-Rosedale Scarborough-Rouge River             York Centre 

                  10684                   10355                    8643 

        Etobicoke North   Scarborough-Agincourt         Don Valley East 

                   8240                    7996                    7688 

              York West 

                   7085 



In reply to Edgardo Torres

Re: Assignment 4 Section "e"

by Erik Spence -
Those numbers are way too big. Did you not filter for 311 or September?
In reply to Erik Spence

Re: Assignment 4 Section "e"

by Edgardo Torres -
Perfect, thank you very much, slicing was exactly my problem. Thanks for the tip.
In reply to Liane Phung

Re: Assignment 4 Section "e"

by Madison Argo -
Hi Liane!
I am getting Beaches-East York (32) as the most too. I started part e) by converting the date to a string and then isolating the month using the substr() command. Then I spliced the division and the month. Then used sort and table to calculate the total number of service calls and ended up with the Beaches-East York (32) result. I am certain I probably did something wrong but not exactly sure where
In reply to Madison Argo

Re: Assignment 4 Section "e"

by Liane Phung -
Hi Madison,
I realized in my code I didn't actually splice for "311" as a unique Division itself which is why I got Beaches-East York. As Erik suggested, check the numbers - when I spliced for both "311" and September the numbers dropped to less than 100 per division in order to get Trinity-Spadina.
In reply to Edgardo Torres

Re: Assignment 4 Section "e"

by Leanna Lui -
I have the same question! After sorting the table of frequencies, I'm having trouble extracting the name of the ward. Any tips would be greatly appreciated!
In reply to Leanna Lui

Re: Assignment 4 Section "e"

by Leanna Lui -
Never mind, solved!
In reply to Leanna Lui

Re: Assignment 4 Section "e"

by Nicholas Ainsworth -
Hi Leanna,

I'm having the same issue!

Do you have any pointers for this? I've tried using "tail" on the sorted table but it extracts the column header and frequency data, not just the name of the ward.
In reply to Nicholas Ainsworth

Re: Assignment 4 Section "e"

by Nicholas Ainsworth -
Never mind, figured it out as well.

In case anyone else is having trouble, I found the `name()` function helpful for this step.