Learn R Programming

vegtable (version 0.1.7)

crosstable: Generating cross tables from database lists

Description

This function is generating cross tables, which are the most common format used by statistical packages analysing vegetation data (e.g. vegan::vegan).

Most applications and displays of vegetation data use preferentially the cross table format. For convenience, the formula has the form abundance ~ plot + species + \ldots{}. Additional variables used for rows (\ldots{}) can be for instance the layers.

For objects of class vegtable, the formula can also include variables from the species list (for example AcceptedName, AuthorName) or even taxon traits.

Usage

crosstable(formula, data, ...)

# S4 method for formula,data.frame crosstable( formula, data, FUN, na_to_zero = FALSE, use_nas = TRUE, as_matrix = FALSE, ... )

# S4 method for formula,vegtable crosstable(formula, data, FUN, na_to_zero = FALSE, use_nas = TRUE, ...)

cross2db(object, layers = FALSE, na_strings)

Value

An object of class data.frame.

Arguments

formula

A formula indicating the variables used in the cross table.

data

Either a data frame or an object of class vegtable.

...

Further arguments passed to the function stats::aggregate().

FUN

Function used to aggregate values.

na_to_zero

A logical value indicating whether zeros should be inserted into empty cells or not.

use_nas

Logical value indicating whether NAs should be considered as levels for categorical variables or not.

as_matrix

A logical value, whether output should be done as matrix or data frame.

object

A data frame including a cross table.

layers

Logical value, whether the cross table includes a layer column or not.

na_strings

Character vector indicating no records in the cross table.

Author

Miguel Alvarez kamapu78@gmail.com

Examples

Run this code
Kenya_veg <- subset(Kenya_veg, REFERENCE == 2331, slot="header")

## transform cover to percentage
Kenya_veg <- cover_trans(Kenya_veg, to="cover_perc", rule="middle")

## cross table of the first 5 plots
Cross <- crosstable(cover_perc ~ ReleveID + AcceptedName + AuthorName,
        Kenya_veg[1:5,], mean, na_to_zero=TRUE)
head(Cross)

Run the code above in your browser using DataLab