To get the L_var for a certain set of numbers I believe this would work:
l_var = sd(x) / mean(x)
where x
is the vector of numbers. Next we wrap it in a function:
l_var = function(x) sd(x) / mean(x)
outcome = l_var(input)
where input
is a vector of numbers, and outcome
the outcome of the math equation.
If your timestamp column is of class POSIXlt
, you can use strftime
to create a factor column where you categorize your data. See this SO answer for more details on this step. Next you can use ddply
from the plyr
package to get the l_var
per category (say a day):
result = ddply(df, .(cat), summarise, l_var = l_var(value))
where df
is the input data.frame where cat
is the time category, and value the x
value in your equation above. To write the result to file you can use write.csv
:
write.csv(result, file = "out.csv")
I think this covers about all the steps...