r - How can I extract the month using sqldf package -
i tried view based on group of date using sqldf package , month function got error :error in sqlitesendquery(con, statement, bind.data) : error in statement: no such function: month
here query: s<-sqldf("select month(datetime),sum(wolfs) group datetime")
attached toy data frame:
df <- read.table(text = "datetime birds wolfs snakes 2014-05-21 9 7 2014-04-28 8 4 b 2014-04-13 2 8 c 2014-03-12 2 3 2014-02-04 8 3 2014-02-29 1 2 2014-01-17 7 1 b 2014-01-16 1 5 c 2014-09-20 9 7 c 2014-08-21 8 7 c ",header = true)
how can extract month using sqldf package?
i suspect used sql server, sqldf
backend being used in case sqlite, there no month
function. try instead:
r> sqldf("select strftime('%m', datetime) month ,sum(wolfs) wolves df group strftime('%m', datetime)") # month wolves # 1 01 6 # 2 02 5 # 3 03 3 # 4 04 12 # 5 05 7 # 6 08 7 # 7 09 7
Comments
Post a Comment