[R] Group by
Henrique Dallazuanna
wwwhsd at gmail.com
Thu Mar 11 13:16:10 CET 2010
Try this:
DF <- read.csv(textConnection("V1,V2,V3
10:03:13,3.4,1002
10:03:14,5.6,1001
10:05:27,7.2,999
10:05:33,8.2,998"), header = TRUE)
tDates <- strptime(DF$V1, "%H:%M:%S")
tDates[[2]] <- floor(strptime(DF$V1, "%H:%M:%S")[[2]] / 5) * 5
aggregate(DF[,c('V2', 'V3')],
list(format(tDates, "%H:%M:00")),
FUN = sum)
On Thu, Mar 11, 2010 at 6:48 AM, ManInMoon <xmoon2000 at googlemail.com> wrote:
>
> I have a matrix with a POSIXct as a numeric in the first column.
>
> I would like to create a new matrix that is "grouped by" my chosed time
> bars.
>
> i.e. So I would like to group by hour or day or 5 days, and have all my
> columns be summed or averaged or counted..
>
> mydata:
>
> V1,V2,V3
> 10:03:13,3.4,1002
> 10:03:14,5.6,1001
> 10:05:27,7.2,999
> 10:05:33,8.2,998
>
> I want to convert this into say 5 minutes "bars" and sum columns
>
> mynewdata:
>
> V1,V2,V3
> 10:00:00,9.0,2003
> 10:05:00,15.4,1997
>
>
> How can I do this?
> --
> View this message in context: http://n4.nabble.com/Group-by-tp1588694p1588694.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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list