Here's an R script for loading nine completely different community data sets, each associated with a matrix of environmental data. Most of the data comes from this wonderful website,
# Forest vegetation data from Vltava river valley
vltava.spe <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/vltava-spe.txt",
row.names = 1)
vltava.env <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/vltava-env.txt",
row.names = 1)
# Vegetation of acidophilous grasslands in Třebíč region
grasslands.spe <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/grasslands-spe.txt",
row.names = 1)
grasslands.env <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/grasslands-env.txt")
# Vegetation of Carpathian wetlands
bryo <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/bryophytes.txt",
row.names = 1)
vasc <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/vasc_plants.txt",
row.names = 1)
chem <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/chemistry.txt",
row.names = 1)
# Vegetation data from Bryce Canyon (Utah, USA)
library(labdsv)
data(bryceveg) # matrix with species data (160 samples in rows and 169 species in columns)
data(brycesite) # matix of environmental variables (160 samples in rows and 11 environmental variables in columns)
# Experimental data from wet meadow
ohrazeni.spe <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/ohrazeni-spe.txt",
row.names = 1)
ohrazeni.env <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/ohrazeni-env.txt")
# Tropical forest permanent plot in Barro Colorado Island (Panama)
# install.packages(vegan) install.packages(BiodiversityR)
library(vegan)
data(BCI)
library(BiodiversityR)
data(BCI.env)
# Community of coral reefs around Tikus island, Indonesia
tikus.spe <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/tikus-spe.txt",
row.names = 1)
tikus.env <- read.delim("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/tikus-env.txt")
# Doubs river fish communities
doubs.spe <- read.csv("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/DoubsSpe.csv",
row.names = 1)
doubs.env <- read.csv("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/DoubsEnv.csv",
row.names = 1)
doubs.spa <- read.csv("http://www.sci.muni.cz/botany/zeleny/wiki/anadat-r/data-download/DoubsSpa.csv",
row.names = 1)
# Oribatid mites
library(vegan)
data(mite)
data(mite.env)
We begin by making a vector with the names of the data sets, so we can refer to all the data simultaneously,
does.char.refer.to.data <- function(x) class(eval(parse(text = x))) == "data.frame"
data.objects <- ls()[sapply(ls(), does.char.refer.to.data)]
Here's a function that can be used to do the same thing to every dataset,
#' Character apply
#'
#' Pass several objects through a function where the objects
#' are refered to by character strings.
#'
#' @param objects Character vector with object names
#' @param FUN Function to apply
#' @param ... Additional arguments to pass to FUN
capply <- function(objects, FUN, simplify = TRUE, ...) {
# differentiate between names (obj.names) and strings (objects) (currently
# only necessary for naming the elements of the output)
obj.names <- lapply(objects, as.name)
# apply the function
out <- lapply(obj.names, function(xx) FUN(eval(xx), ...))
# put characters back in the names attribute
names(out) <- objects
if (simplify)
out <- simplify2array(out)
return(out)
}
Here are some examples of getting info,
# capply(data.objects, dimnames, simplify = FALSE) # prints way too much!
capply(data.objects, dim) # gives you the size of the data
## BCI BCI.env brycesite bryceveg bryo chem doubs.env doubs.spa
## [1,] 50 50 160 160 70 70 30 30
## [2,] 225 6 11 169 30 15 11 2
## doubs.spe grasslands.env grasslands.spe mite mite.env ohrazeni.env
## [1,] 30 48 48 70 70 96
## [2,] 27 16 171 35 5 33
## ohrazeni.spe tikus.env tikus.spe vasc vltava.env vltava.spe
## [1,] 96 60 60 70 97 97
## [2,] 86 2 75 123 24 342