Assignment 4 Part 1: D

Assignment 4 Part 1: D

by Tulip Marawi -
Number of replies: 10

Hello! Could I ask someone to point me in the right direction with regards to Part 1D of the assignment? I have tried to use the nrow function, and in parenthesis I spliced my dataframe for "Service Request Type", and specified "Dead Animal On Expressway". However, when I use cat to display my answer, I am getting "0" as an answer (not 15). Thank you!

In reply to Tulip Marawi

Re: Assignment 4 Part 1: D

by Tibyan Ahmed -
Hey Tulip, I ran into the same problem but what I ended up doing was using basically same slicing rational in assignment2 where we had to find out the number of people born in the years after 1991.

Also I realized that R is case sensitive, I kept putting "Dead Animal on Expressway" instead of "Dead Animal On Expressway."
In reply to Tibyan Ahmed

Re: Assignment 4 Part 1: D

by Cong Lu -
Hi Tibyan, I think it is "Dead Animal On Expressway".
here is the test result:
"Dead Animal On Expressway" %in% type.list
[1] TRUE
In reply to Tulip Marawi

Re: Assignment 4 Part 1: D

by Cong Lu -
How did you sliced data frame? Is it still data frame or vectors after you sliced?
it happened to me before, the slicing result was vectors rather than data frame, so nrow is 0.
In reply to Cong Lu

Re: Assignment 4 Part 1: D

by Tulip Marawi -
Thank you for your response! Could you please elaborate on what you mean by slicing result was vector instead of dataframe? It seems like my slicing result was vectors too, I'm unsure how to make it give a dataframe slicing result. This is how I currently have it:
dataframe name[dataframe name$"column name" == "element name", ]
In reply to Tulip Marawi

Re: Assignment 4 Part 1: D

by Cong Lu -
Your code to slice data frame is similar to mine . I think the result should be data frame. But I'm confused why got vector.
Anyway for this part D you could try length() for vectors to get the number.
In reply to Tulip Marawi

Re: Assignment 4 Part 1: D

by Tibyan Ahmed -
Hey Tulip, sorry just saw this, I'm clearly terrible with threads. I elaborated more at the bottom in response to Cong, 10:42pm time stamp smile
In reply to Tulip Marawi

Re: Assignment 4 Part 1: D

by Nahla FadlElMawla -
don't know if this will help, but I don't think you should put "" around the column name try this dataframe$column name == "element name"
In reply to Cong Lu

Re: Assignment 4 Part 1: D

by Tibyan Ahmed -
Hey Cong,

Np, I can expand on what I did. Similarly to how we stored 1991 in a variable in assignment2, I did the same for this part. E.g. x<-"Dead Animal On Express Way" then used this in my slicing.

carcass.req.calls<-df[df$Service.Request.Type == x, ]. Same syntax from lecture 4 slide 22 is where I got this from.
To verify that this was still a data.frame I ran class(carcass.req.calls) and it gave me "data.frame" as the output. Handy command. Let me know if this doesn't make sense.
In reply to Tibyan Ahmed

Re: Assignment 4 Part 1: D

by Cong Lu -
Thank you Tibyan! I see why I got vector after slicing. I used dataframe[dataframe$"column name1" == "element name", "column name2"]