Hello,

 

I am trying to use the projection.matrix( ) function and am following the
example given. I have my data formatted very similar to the test.census
example. 

 

 

> str(AsMi05mat)

`data.frame':   1854 obs. of  6 variables:

 $ Tag      : num  501 502 503 504 505 506 507 508 509 510 ...

 $ Year     : int  1995 1995 1995 1995 1995 1995 1995 1995 1995 1995 ...

 $ Length   : num  34 37 11 24 7 44 4 7 12 20 ...

 $ Flowering: int  1 1 0 1 0 1 0 0 0 1 ...

 $ Fruits   : int  22 22 0 89 0 15 0 0 0 0 ...

 $ Stage    : Factor w/ 5 levels "","Dead","Dormant",..: 4 4 5 4 5 4 5 5 5 4
...

 

The example data includes three years but only shows how to create a matrix
from year 1 to 2. I have 13 years of data and would like to automate creating
all matrices for each pair of years. 

 

My code is the following:

 

AsMi05mat <- read.csv("C:/AsMi05mat.csv")

 

library(popbio)

library(base)

 

##for(i in 1995:2005){

      

##    AsMitrans.i <- subset(merge(AsMi05mat, AsMi05mat, by = "Tag", sort =
FALSE),

##                Year.x == i & Year.y == (i+1) )

##}

 

AsMi05trans <- subset(merge(AsMi05mat, AsMi05mat, by = "Tag", sort = FALSE),

                  Year.x == 1995 & Year.y == 1996 )

 

stages <- c("Vegetative", "Reproductive", "Dead", "Dormant")

 

projection.matrix(AsMi05trans, stage=Stage.x, fate=Stage.y,

                  sort=stages, TF=TRUE)

 

 

I tried a for( ) loop but don't know how to assign new names for each matrix
so end up with only the final comparison (2005 to 2006). I assume an apply( )
function is the way to go but can't see how to do it. 

 

Thanks for any help!

 

Michelle

 


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to