[R] Constructing a transition matrix

From: Chris Stubben <stubben_at_lanl.gov>
Date: Wed 07 Dec 2005 - 07:13:44 EST


Hi,

I would like to construct a transition matrix from a data frame with annual transitions of marked plants.

plant<-c(1:6)
class<-c("seed","seed", "seed", "veg", "rep", "rep") fate<-c("dead", "veg","veg","rep", "rep", "veg")

trans<-data.frame(plant, class, fate)

   plant class fate

1     1  seed dead
2     2  seed  veg
3     3  seed  veg
4     4   veg  rep
5     5   rep  rep
6     6   rep  veg

I have been using sql queries to do this, but I would like to construct the matrix in R since I plan to resample transitions using trans[sample(nrow(trans), 6, replace=T), ]

I know I can get the original size vector using table()

data.matrix(table(trans$class))

      [,1]
rep     2
seed    3
veg     1


but I don't know how to get counts of each class-fate combination where fate does NOT equal dead

seed veg  = 2
veg  rep  = 1
rep  rep  = 1
rep  veg  = 1


or how to divide the class-fate count by the original class count in the size vector to get survival probabilities

seed veg  = 2 / 3 seed = 0.67
veg  rep  = 1 / 1 veg  = 1
rep  rep  = 1 / 2 rep  = 0.5
rep  veg  = 1 / 2 rep  = 0.5


or construct the square matrix with rows and columns in the same developmental sequence like dev<- c("seed","veg", "rep").

      seed veg   rep
seed    0   0     0
veg  0.67   0   0.5
rep     0   1   0.5

Any help or suggestions would be appreciated. Thanks,

Chris Stubben

--
Los Alamos National Lab
BioScience Division
MS M888
Los Alamos, NM 87545

______________________________________________
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 Wed Dec 07 07:45:34 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:30 EST