on a SQLite database with weather informations (colums: DATE, DOY, TEMPERATURE) I like to add a new column with temperature sums (the sum of daily TEMPERATURE from January 1 to the current day). (DOY is the day of the year.)
The dplyr windows functions should be suitable to solve this problem. http://cran.r-project.org/web/packages/dplyr/vignettes/window-functions.html. Perhaps something like
mutate(TEMPERATURESUM = lag(TEMPERATURE, DOY, order_by=DATE))
but it gives an error in statement: no such function: LAG
Do you know an example from which I see how I'm doing it correct? I do not like to use pure SQL where there are so comfortable ways with dplyr.
thx Christof
mtcars %>% mutate(lagged = lag(mpg, 1, order_by=carb))
seems to work. What type of object are you piping tomutate
? What dplyr version are you using? – MrFlicklag
asLAG
– David Robinsonlag
is converted to LAG in SQL (SQL is case insensitivity) and LAG does not exist in SQL :( @docendo thx for the tipp, but unfortunately I get the same error withcumsum
because it seems not to be translated in an SQL equivalent – ckluss