So I was supposed to create a function to get a crime name (w/o using readline), print the average rate for that crime and then name the states with more than the average rate. I got the the print the crime and average rate but I cannot list the names of states with more than the average. I put down something but it is only listing the number of the state with TRUE or FALSE.
Here' s my code:
f_high_crime_rate_states <- function(){
x <- readline(prompt = "Enter a crime name: ")
a <- mean(FBI_Data$Murder)
b <- mean(FBI_Data$Rape)
c <- mean(FBI_Data$Robbery)
d <- mean(FBI_Data$Assault)
e <- mean(FBI_Data$PropertyCrime)
f <- mean(FBI_Data$Burglary)
g <- mean(FBI_Data$VehicleTheft)
h <- mean(FBI_Data$LarcenyTheft)
i <- mean(FBI_Data$ViolentCrime)
if(x == "Murder"){
paste("The rate is: ",a,
"The states with more than average include: ", (a < FBI_Data$Murder))
}else if(x == "Violent Crime"){
paste("The rate is: ",i,
"The states with more than average include: ", (i < FBI_Data$ViolentCrime))
}else if(x == "Rape"){
paste("The rate is: ", b,
"The states with more than average include: ", (b < FBI_Data$Rape))
}else if(x == "Robbery"){
paste("The rate is: ", c,
"The states with more than average include: ", (c < FBI_Data$Robbery))
}else if(x == "Assault"){
paste("The rate is: ", d,
"The states with more than average include: " (d < FBI_Data$Assault))
}else if(x == "Property crime"){
paste("The rate is: ", e,
"The states with more than average include: ", (e < FBI_Data$PropertyCrime))
}else if(x == "Burglary"){
paste("The rate is: ", f,
"The states with more than average include: ", (f < FBI_Data$Burglary))
}else if(x == "Vehicle theft"){
paste("The rate is: ", g,
"The states with more than average include: ", (g < FBI_Data$VehicleTheft))
}else{
paste("The rate is: ", h,
"The states with more than average include: ", (h < FBI_Data$LarcenyTheft))}
}
f_high_crime_rate_states()
And here's a picture of the data set: