en:data:gentry:extract-gentry-plots
Script for compiling Gentry's forest transects from Excel file
I downloaded zip file with all plots, unzipped file into prepared folder (in this case into c:/gentry/; this directory will contain subfolders africa, europe etc.). The original data contain many formatting errors, which I had to manually remove in the original Excel files; therefore, if you use the original files from www.mobot.org with this R code, you will not receive the same result as I did (consider using data modified by me, available here).
Then, I used the following script to extract the data:
# install.packages ('XLConnect') # install if not yet installed library (XLConnect) setwd ('c:\\gentry\\') # set to the directory where you unzipped all_excel.zip file folders <- dir () file.name <- NULL for (fo in folders) { setwd (fo) for (fi in dir ()) file.name <- append (file.name, paste (getwd (), fi, sep = '/')) setwd ('..') } gentry <- lapply (file.name, FUN = function (x) { print (x) data <- readWorksheetFromFile (x, sheet = 1) sp.names <- data [, 2:4] sp.names <- apply (sp.names, 1, paste, collapse = ' ', sep = ' ') res.tab <- as.data.frame (as.matrix (xtabs (data[,14] ~ as.numeric (data[,1]) + sp.names, sparse = T))) res.tab }) # the following deletes the plots with less than 10 subplots (or with other deviations) n <- 1 for (del in which (lapply (gentry, nrow) >= 10)) {gentry197[[n]] <- gentry[[del]]; n <- n+1} length (gentry197) # should be 197 which (sapply (gentry197, nrow) != 10) # liesjvar sierraro araracua cueva riomanso potomac newcaldo # manually remove zeros in sierraro, araracua, riomanso and newcaldo, and replace ' by 1 in cueva # these two localities have 11 plots - choose only first 10 gentry197$liesjvar <- gentry197$liesjvar[1:10,] gentry197$potomac <- gentry197$potomac[1:10,] which (sapply (gentry197, nrow) != 10) # none save (gentry197, file = 'gentry197.r') # saves resulting list with 197 tables
en/data/gentry/extract-gentry-plots.txt · Last modified: by David Zelený
