Skip to content

Ardisia elliptica

Chris Stubben edited this page Feb 9, 2017 · 12 revisions

The following code will download the projection matrices in Appendix E from

Koop and Carol C. Horvitz. 2005. Projection matrix analysis of the demography of an invasive, nonnative shrub (Ardisia elliptica). Ecology 86:2661–2672

In this example, the readHTMLTable function will return a list of 5 data.frames, one for each population. Each population has three matrices except for Schinus Thicket below.

url <- "http://www.esapubs.org/archive/ecol/E086/142/appendix-E.htm"
x <- readHTMLTable(url, stringsAsFactors=FALSE)
length(x)
x[[5]]  
           V1    V2    V3                     V4    V5    V6    V7     V8     V9
1    Stage at                   Stage at time t                      <NA>   <NA>
2  time t + 1    SD    SG                     SJ    MJ    LJ    PR     SA     LA
3                                                                               
4                         Schinus Thicket - 1999                     <NA>   <NA>
5          SD     0     0                      0     0  28.9  86.7 124.69 213.33
6          SG 0.017 0.312                      0     0     0     0      0      0
7          SJ     0 0.624                  0.738 0.034     0     0      0      0
8          MJ     0     0                   0.24 0.517     0     0      0      0
9          LJ     0     0                  0.004 0.172 0.167     0      0      0
10         PR     0     0                  0.009 0.276   0.5     0      0      0
11         SA     0     0                      0     0 0.333 1.000  0.700  0.017
12         LA     0     0                      0     0     0     0  0.300  0.978

To format the 13 matrices, I combine the list elements, select only rows with a number, split the frame into a list and convert the data.frames to a numeric matrix.

y <- do.call("rbind", x)
z <- subset(y, grepl("[0-9]", y[,2]), -1)
arel <- split( z, rep(1:13, each=8))
arel <- lapply(arel, data.matrix)

A few final steps are needed to add stage class names to the matrices (taken from the second row) and population-year to the list names.

stages <- unlist(x[[1]][2,-1]) 
arel <- lapply(arel, function(x){ dimnames(x) <-list(stages, stages); x})
#pop <- grep(" - ", y[,4], value=TRUE) # some with &nbsp; OR
pop <- c(paste(rep(c("FE", "TF", "HF", "AT") , each = 3), c("99", "00", "01"), sep = ""), "ST99")
names(arel) <- pop
sapply(arel, lambda)
 FE99  FE00  FE01  TF99  TF00  TF01  HF99  HF00  HF01  AT99  AT00  AT01  ST99 
1.039 0.993 1.002 1.296 1.060 1.133 1.071 1.033 1.098 1.053 1.088 0.999 1.304 
image2(arel[[1]])

image2

Clone this wiki locally