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.
Use mutate to change the date before you use group_by. Posting incomplete fragments in your questions is usually not enough to get useful help with R on the internet. Please add the extra few lines of code that would make it reproducible [1] from now on. [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On August 22, 2015 12:43:05 AM PDT, 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.
Do an str() on the data. It looks like your variable is an integer where you probably need a date or a factor. Would you please include some sample data if possible. See ?dput which is the preferred way for sending sample data. It ensures that the reader is looking at the exact same data that you have on your machine. If the data set is large a small, representative sample is find. Something like dput(head(dat1, 100)) is probably fine. Fake data is okay if it is in the same format as the real. Check with str() before sending. John Kane Kingston ON Canada> -----Original Message----- > From: shivibhatia at ymail.com > Sent: Sat, 22 Aug 2015 00:43:05 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] Date as Integer > > 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.____________________________________________________________ Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account.
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]]
Hi John, Sorry but if this sounds really as a newbie question. I looked at the data as you suggested using glimpse(name of the dataset) and then View(dput(head(ak,20))) to capture it as a table. Is there an option where i can save this view table & share along. I used dput but that would not work as it is not giving data out in the required format due to multiple columns. Please suggest on view. Also i tried mutate but still get the same error message: Error in UseMethod("group_by_") : no applicable method for 'group_by_' applied to an object of class "c('integer', 'numeric')". Please see the output from View(dput(head(ak,20))) Observations: 379674 Variables: $ waybill (int) 43360533, 43361203, 42754126, 43154067... $ branch (fctr) GURGAON-25, GURGAON-25, AHMEDABAD-03,... $ type (fctr) FMC, FMC, RBA, HBA, HBA, HBA, RBA, RB... $ pickdate (fctr) 2015/06/21, 2015/06/22, 2015/06/04, 2... $ city (fctr) Gurgaon, Gurgaon, Ahmedabad, Vapi, Va... $ bookingzone (fctr) G-N1, G-N1, G-W1, G-W1, G-W1, G-W1, G... $ destinationzone (fctr) G-N1, G-N1, G-W1, G-W1, G-W1, G-W1, G... $ state (fctr) G-N1, G-N1, G-W1, G-W1, G-W1, G-W1, G... $ mod (fctr) AIR, AIR, SURFACE, AIR, AIR, SURFACE,... $ mode_payment (fctr) CREDIT, CREDIT, TOPAY, CREDIT, CREDIT... $ delivery_gateway (fctr) KANNUR, KANNUR, KANNUR, KANNUR, KANNU... $ delivery_date (fctr) 7/8/2015, , 6/20/2015, 6/13/2015, 6/1 Does this help? -- View this message in context: http://r.789695.n4.nabble.com/Date-as-Integer-tp4711377p4711456.html Sent from the R help mailing list archive at Nabble.com.