I have the following table:
Date Country Class Value 6/1/2010 USA A 45 6/1/2010 Canada A 23 6/1/2010 Brazil B 65 9/1/2010 USA B 47 9/1/2010 Canada A 98 9/1/2010 Brazil B 25 12/1/2010 USA B 14 12/1/2010 Canada A 79 12/1/2010 Brazil A 23 3/1/2011 USA A 84 3/1/2011 Canada B 77 3/1/2011 Brazil A 43 6/1/2011 USA A 45 6/1/2011 Canada A 23 6/1/2011 Brazil B 65 9/1/2011 USA B 47 9/1/2011 Canada A 98 9/1/2011 Brazil B 25 12/1/2011 USA B 14 12/1/2011 Canada A 79 12/1/2011 Brazil A 23 3/1/2012 USA A 84 3/1/2012 Canada B 77 3/1/2012 Brazil A 43
In the column "Date" the years are divided into the following months - March, June, September and December. I need to group the months from June to March as the Fiscal year and in each fiscal year calculate the average value of the “Value” column by “Country” and “Class”. Can someone help me do this?
I try to do this with data.table, but I get an error:
d=data[,list(Val=mean(Value,na.rm=T)),by=list(Country,Class, Period.grp=cut(Period,list(6/1/2010,3/1/2011,6/1/2011,3/1/2012, 6/1/2012,3/1/2013,6/1/2013,3/1/2014)))]
Error in cut.default (Period, list (6/1/2010, 3/1/2011, 6/1/2011, 3/1/2012,: 'x' must be numeric
Thanks!
source share