User Tools

Site Tools


cs:data:gentry:extract-gentry-plots

Skript pro kompilaci Gentryho lesních ploch z Excelovského souboru

Excelovský soubor s jednotlivými soubory roztříděnými do podadresářů podle kontinentů stáhněte zde a odzipujte do adresáře (c:/gentry/ v tomto příkladě, v adresáři budou podadresáře africa, europe etc.).

# 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.short <- NULL
for (fo in folders) 
	{
	setwd (fo)
	for (fi in dir ())
		file.name.short <- append (file.name.short, unlist (strsplit (fi, '.xls'))
)
	setwd ('..')
}
 
file.name.short <- tolower (file.name.short) 
 
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] ~ data[,1] + sp.names, sparse = T)))
	res.tab
	})
 
names (gentry) <- file.name.short
 
# 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}
names (gentry197) <- names (which (lapply (gentry, nrow) >= 10))
 
length (gentry197)  # should be 197
 
save (gentry197, file = 'gentry197.r')  # saves resulting list with 197 tables
cs/data/gentry/extract-gentry-plots.txt · Last modified: 2017/10/11 12:36 (external edit)