[R] sum per day

Rui Barradas ruipbarradas at sapo.pt
Tue Nov 27 11:51:02 CET 2012


Hello,

Try


aggregate(Hunger ~ cut(myframe2$myframestime, "day"), data = myframe2, 
FUN = sum)

Hope this helps,

Rui Barradas
Em 27-11-2012 09:13, Tagmarie escreveu:
> Hello,
>
> I have a data frame somewhat like this one:
>
> myframe <- data.frame (Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00",
> "24.09.2012 11:00",
>                                     "25.09.2012 09:00", "25.09.2012 10:00",
> "25.09.2012 11:00"), Hunger=c(1,1,1,2,2,1) )
> myframestime <- as.POSIXct (strptime(as.character(myframe$Timestamp),
> "%d.%m.%Y %H:%M"), tz="GMT")
> myframe2 <- cbind (myframe,myframestime)
> myframe2$Timestamp <- NULL
> myframe2
>
> Now I want to get the sum of "Hunger" for each day. In the end I want
> something which looks like the following dataframe:
>
> myoutcome <- data.frame(Timestamp=c("24.09.2012", "25.09.2012"),
> sumHunger=c(3, 5))
>
> Does anyone know how to do that?
> That would be very helpful and to all people who are willing to help me:
> Thank you in advance!
>
> Best regards,
> Tagmarie
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/sum-per-day-tp4650937.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.




More information about the R-help mailing list