[R] Date as Integer
William Dunlap
wdunlap at tibco.com
Sat Aug 22 18:47:40 CEST 2015
It would help if you supplied a small dataset so we could
reproduce your problem problem. Here is one that gives the same
error. (I also moved some parentheses around so "%y-%m-%d"
is an argument to as.Date() instead of to group_by().)
data.frame(pickdate=paste(sep="-",15,08,c(21,22,21,22,22)),
waybill=2^(0:4)) %>%
group_by(as.Date(pickdate,"%y-%m-%d")) %>%
summarize(Total=count(waybill))
#Error: no applicable method for 'group_by_' applied to an object of
class "c('double', 'numeric')"
I think count() is a wrapper for summarize() (or summarise() outside the
US),
not something to call from within summarize(), but I may be wrong (the help
file is terse). Try using n() instead:
data.frame(pickdate=paste(sep="-",15,08,c(21,22,21,22,22)),
waybill=2^(0:4)) %>%
group_by(as.Date(pickdate,"%y-%m-%d")) %>%
summarize(N=n(), Sum=sum(waybill), Mean=mean(waybill))
#Source: local data frame [2 x 4]
#
# as.Date(pickdate, "%y-%m-%d") N Sum Mean
#1 2015-08-21 2 5 2.500000
#2 2015-08-22 3 26 8.666667
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Sat, Aug 22, 2015 at 12:43 AM, Shivi82 <shivibhatia at ymail.com> wrote:
> Hi All,
>
> I am using dplyr package and need to find total bills booked grouped on a
> date level however my date is integer.
> In the code below i was trying to change date format from integer. However
> it is throwing an error:
>
> "no applicable method for 'group_by_' applied to an object of class
> "c('integer', 'numeric')"
>
> ak%>%
> group_by(as.Date(pickdate),"%y%m%d")%>%
> summarise(Total=count(waybill))
>
> Do i need to create a new var first changing the date and then group it or
> as.Date will work as i added in dplyr.
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Date-as-Integer-tp4711377.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list