mercredi 8 février 2017

create a function that calculates and retrieves value from a table

Vote count: 0

I have a table with info on driver infractions and value of infractions. I have two columns Value (of infraction) and year (of infraction.) For each year of infraction I have several values. Years go from 2000-2014. I need a function that can retrieve the total of infractions per a "predetermined" year. Ie: when user types year, only get the info of that year. So far I can only manage to get the info of all years at the same time

I tried this. total_year<-function( x=infractions$year){aggregate(infractions$value~infractions$year_deb,FUN=sum, na.rm = TRUE)}

Then I type total_year(2012) = and I get a table of infractions per year enlisting all years, but I only want the total for 2012 thanks

asked 36 secs ago

Let's block ads! (Why?)



create a function that calculates and retrieves value from a table

Aucun commentaire:

Enregistrer un commentaire