Try this:
xtabs(x ~ t + id, data = X)
On Wed, Jul 1, 2009 at 2:35 PM, Young Cho wrote:
> Hi, thanks everyone for any help in advance.
>
> I found myself dealing with a tabular time-series data formatted each row
> like [ time stamp, ID, values]. I made a small examples:
>
> X = data.frame(t
Dear Young,
I am sorry, my bad, it should have been
with(X, tapply(x, list(id, t), function(y) y ))
to get exactly what you asked for.
HTH,
Jorge
On Wed, Jul 1, 2009 at 4:59 PM, Jorge Ivan Velez
wrote:
> Dear Young,
> Try this:
>
> with(X, tapply(x, list(t,id), function(y) y ))
>
> HTH,
>
>
Dear Young,
Try this:
with(X, tapply(x, list(t,id), function(y) y ))
HTH,
Jorge
On Wed, Jul 1, 2009 at 1:35 PM, Young Cho wrote:
> Hi, thanks everyone for any help in advance.
>
> I found myself dealing with a tabular time-series data formatted each row
> like [ time stamp, ID, values]. I
Is this what you want:
> X = data.frame(t=c(1,1,1,2,2,2,2,3,3,3,4,4,4,5,5),id =
+ c('a','b','c','c','b','d','e','b','a','e','a','b','d','b','c'))
> X$x = rnorm(15)
> X
t id x
1 1 a -0.6264538
2 1 b 0.1836433
3 1 c -0.8356286
4 2 c 1.5952808
5 2 b 0.3295078
6 2 d -0.82046
Can't say whether its any faster but read.zoo in the devel version of
zoo can do this using the split= argument where split=2 in the
example below says to split it into time series defined by the
second column.
Lines <- '"t" "id" "x"
1 "a" -1.71941257904109
1 "b" 1.33629503083329
1 "c" 1.613373720
This may be closer; forgot about the NAs
> cast(X.m, id ~ t, function(x) if (length(x)==0) NA else sum(x))
id 1 2 3 4 5
1 a -0.6264538 NA 0.5757814 1.5117812NA
2 b 0.1836433 0.3295078 0.7383247 0.3898432 -2.214700
3 c -0.835628
Hi, thanks everyone for any help in advance.
I found myself dealing with a tabular time-series data formatted each row
like [ time stamp, ID, values]. I made a small examples:
X = data.frame(t=c(1,1,1,2,2,2,2,3,3,3,4,4,4,5,5),id =
c('a','b','c','c','b','d','e','b','a','e','a','b','d','b','c'))
7 matches
Mail list logo