Re: [R] Constructing a transition matrix

From: Chris Stubben <stubben_at_lanl.gov>
Date: Thu 08 Dec 2005 - 04:52:13 EST

Hi Peter,

Thanks for pointing out the set functions. I can use setdiff to find missing rows

setdiff(dev, rownames(A))
[1] "seed"

and intersect to find common rows

d1<- intersect(dev, rownames(A) )
[1] "veg" "rep"

I was trying to use a negative index like A[-1,] to remove the dead row, but d1 is a better solution. Now I can add the missing seed row and get a square matrix.

rbind( seed=numeric(3), A[d1,] )[dev,dev]

Another post by Hans Gardfjell suggested reordering factor levels before using prop.table(table()) and this solution works great!

trans$class <- ordered(trans$class, levels=dev) trans$fate <- ordered(trans$fate, levels=c(dev,"dead") )

A <- t(prop.table(table(trans$class, trans$fate),1))[-4,]

             seed veg rep

   seed 0.0000000   0 0.0
   veg  0.6666667   0 0.5
   rep  0.0000000   1 0.5


Thanks for the help,

Chris

Peter Dalgaard wrote:

> Are you looking for something like
>
> d1 <- setdiff(dev,"seed")
> A0[d1,dev] <- A[d1,dev]
>
> ?



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 Received on Thu Dec 08 05:04:55 2005

This archive was generated by hypermail 2.1.8 : Thu 08 Dec 2005 - 09:31:27 EST