[R] Constructing a transition matrix

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Dec 7 08:27:41 CET 2005


Chris Stubben <stubben at lanl.gov> writes:

> Hi again,
> 
> I almost figured this out, but still need some help on the last part.
> 
> I can use prop.table to get survival probabilities...
> 
> A <- t(prop.table( table(trans$class, trans$fate),1) )
> 
>              rep      seed       veg
>    dead 0.0000000 0.3333333 0.0000000
>    rep  0.5000000 0.0000000 1.0000000
>    veg  0.5000000 0.6666667 0.0000000
> 
> 
> so now I just need to format the matrix.  I thought I could create a 
> matrix of zeroes using size class names,
> 
> dev<- c("seed","veg", "rep").
> 
> 
> A0<-matrix(numeric(9), nrow=3, dimnames=list(dev,dev) )
>       seed veg rep
> seed    0   0   0
> veg     0   0   0
> rep     0   0   0
> 
> 
> but how do I assign values in A to the corresponding rows and columns in 
> A0?  I hope there is an easy solution that I'm overlooking.
> 
> 
>       seed veg   rep
> seed    0   0     0
> veg  0.67   0   0.5
> rep     0   1   0.5
> 

Are you looking for something like

d1 <- setdiff(dev,"seed")
A0[d1,dev] <- A[d1,dev]

?
-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list