You data did not cover a 30 second interval, so I just divided into 2 second
intervals.
> x <- read.csv('/tempxx.txt')
> str(x)
'data.frame': 37 obs. of 5 variables:
$ TranName : Factor w/ 5 levels "MAC00029","MAC00045",..: 1
1 4 1 1 1 4 1 1
5 ...
$ Date.Time: Factor w/ 36 levels "20061027 112500.030",..: 1 2 3 4 5
6 9 7
8 10 ...
$ TimeA : int 703 703 484 812 672 687 453 1000 937 515 ...
$ A.B : int 703 719 500 812 672 687 453 1000 953 515 ...
$ TimeB : int 0 16 16 0 0 0 0 0 16 0 ...> x$Date.Time <- as.POSIXct(strptime(as.character(x$Date.Time),
"%Y%m%d
%H%M%OS"))> # just by transaction
> aggregate(x[,c("TimeA", "TimeB")],
list(tran=x$TranName), mean)
tran TimeA TimeB
1 MAC00029 973.6897 4.275862
2 MAC00045 359.0000 0.000000
3 MAC00054 1047.0000 31.000000
4 MAC00056 596.8000 9.400000
5 MAC00062 515.0000 0.000000> # break time into 2 second intervals
> x.time <- seq(trunc(min(x$Date.Time), units='sec'),
+ trunc(max(x$Date.Time+1), units='sec'), by="2
sec")> aggregate(x[, c("TimeA", "TimeB")],
list(tran=x$TranName,
+ time=cut(x$Date.Time, breaks=x.time)), mean)
tran time TimeA TimeB
1 MAC00029 2006-10-27 11:25:00 739.3333 5.333333
2 MAC00056 2006-10-27 11:25:00 484.0000 16.000000
3 MAC00029 2006-10-27 11:25:02 878.0000 6.400000
4 MAC00054 2006-10-27 11:25:02 1047.0000 31.000000
5 MAC00056 2006-10-27 11:25:02 453.0000 0.000000
6 MAC00062 2006-10-27 11:25:02 515.0000 0.000000
7 MAC00029 2006-10-27 11:25:04 1048.3636 4.181818
8 MAC00056 2006-10-27 11:25:04 453.0000 0.000000
9 MAC00029 2006-10-27 11:25:06 1009.7000 3.000000
10 MAC00045 2006-10-27 11:25:06 359.0000 0.000000
11 MAC00056 2006-10-27 11:25:06 797.0000 15.500000>
>
On 11/7/06, Bin Chen <nxrwdate@yahoo.com> wrote:>
> Hi,
>
> Our in-house AS400 based application produce a timer file as follows:
>
> TranName,Date Time, TimeA,A+B, TimeB
> MAC00029,20061027 112500.030,703,703,0
> MAC00029,20061027 112500.342,703,719,16
> MAC00056,20061027 112500.920,484,500,16
> MAC00029,20061027 112501.186,812,812,0
> MAC00029,20061027 112502.092,672,672,0
> MAC00029,20061027 112502.264,687,687,0
> MAC00056,20061027 112503.264,453,453,0
> MAC00029,20061027 112502.920,1000,1000,0
> MAC00029,20061027 112502.967,937,953,16
> MAC00062,20061027 112503.592,515,515,0
> MAC00054,20061027 112503.873,1047,1078,31
> MAC00029,20061027 112503.857,1094,1110,16
> MAC00029,20061027 112504.029,1094,1094,0
> MAC00029,20061027 112504.029,1297,1313,16
> MAC00029,20061027 112504.373,969,969,0
> MAC00056,20061027 112505.373,453,453,0
> MAC00029,20061027 112504.670,1219,1219,0
> MAC00029,20061027 112505.061,968,968,0
> MAC00029,20061027 112504.873,1297,1312,15
> MAC00029,20061027 112505.029,1141,1156,15
> MAC00029,20061027 112505.342,843,843,0
> MAC00029,20061027 112505.560,844,844,0
> MAC00029,20061027 112505.701,891,891,0
> MAC00029,20061027 112505.623,969,969,0
> MAC00029,20061027 112506.076,1016,1016,0
> MAC00029,20061027 112506.185,907,907,0
> MAC00056,20061027 112506.404,844,859,15
> MAC00029,20061027 112506.232,1110,1125,15
> MAC00029,20061027 112506.310,1032,1047,15
> MAC00029,20061027 112506.701,703,703,0
> MAC00029,20061027 112506.107,1391,1391,0
> MAC00029,20061027 112506.264,1234,1234,0
> MAC00029,20061027 112506.514,984,984,0
> MAC00056,20061027 112506.904,750,766,16
> MAC00045,20061027 112507.420,359,359,0
> MAC00029,20061027 112506.810,1032,1032,0
> MAC00029,20061027 112507.154,688,688,0
>
> How do I user R to sort out by Transaction name, then average the TimeA
> and TimeB over 30 seconds
> interval?
>
> I have just started to lear R, but this task seems to be hard to me, so I
> would like to know if
> this is possible at all. Thanks a lot for your help.
>
>
>
>
>
>
>
>
____________________________________________________________________________________
> Sponsored Link
>
> Degrees online in as fast as 1 Yr - MBA, Bachelor's, Master's,
Associate
> Click now to apply http://yahoo.degrees.info
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
[[alternative HTML version deleted]]