Date: Tue, 22 Mar 2005 11:20:40 -0500
From: Ingmar Visser <i.visser at uva.nl>
Sender: r-help-bounces at stat.math.ethz.ch
Cc:
Precedence: list
User-Agent: Microsoft-Entourage/11.1.0.040913
Hi All,
Does someone have an idea of how to cleverly convert a categorical
timeseries into a transition matrix?
Ie, I have something like:
x<- c(1,1,2,1,1,2,2,2,1,2),
And I want a matrix with counts and/or probabilities:
tr <- matrix(c(2,3,2,2),2,2)
tr
[,1] [,2]
[1,] 2 2
[2,] 3 2
Meaning that there are two transitions from 1 to 1, two from 1 to 2, three
from 2 to 1 and two from 2 to 2.
Using for loops etc this is of course no problem, but I am curious whether
there is a smarter solution.
Any hints appreciated, Ingmar
--
Ingmar Visser
Department of Psychology, University of Amsterdam
Roetersstraat 15, room 1009
1018 WB Amsterdam
The Netherlands
http://users.fmg.uva.nl/ivisser/
tel: +31-20-5256735