[R] Oh apply functions, how you confuse me

LCOG1 jroll at lcog.org
Thu Sep 1 19:11:28 CEST 2011

Hi guys, 
I have a crap load of data to parse and have enjoyed creating a script that
takes this data and creates a number of useful graphics for our area.  I am
unable to figure out one summary though and its all cause I dont fully
understand the apply family of functions.  Consider the following:

#Create data 

#Example calc

#Sum Volume by 5 minute break by Day by Direction

The data is a snap shot of what im working with and I am trying to get to
something similar to the last line where the volumes are summed.  What i
want to do is to do a weighted average for the speed by 5 minute break.  So
for all the speeds and volumes in a given hour of 5 minute break(12 per
hour), i would want to 

sum(Volumes[1:12]*Speed[1:12]) / sum(Volumes[1:12]

The output resembling the one from the above but having these weighted
values.  I am assuming the sum function in the above would be replaced by a
function doing the calculation but I am still not sure how to do this using
apply functions, so perhaps this isnt the best option.  

Hope this is clear and hope you guys(and of course ladies) can offer some


View this message in context: http://r.789695.n4.nabble.com/Oh-apply-functions-how-you-confuse-me-tp3784212p3784212.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list