Skip to contents

cross table is the most common format required by statistical packages used to analyse vegetation data (e.g. vegan).

You may use for convenience a formula as 'abundance ~ plot + species + ...'. Additional variables used for rows (...) 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.

If required, tables already formatted as cross tables can be converted into column-oriented tables by using the function cross2db().


crosstable(formula, data, ...)

# S4 method for formula,data.frame
  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)



A formula indicating the variables used in the cross table. This formula can be represented as 'abundance ~ cols + rows', where 'abundance' is the numeric variable quantified for a row in a column, for instance the abundance of a species in a plot. Further variables can be set as additional rows indices in a cross table.


Either a data frame or an object of class vegtable.


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


Function used to aggregate values in the case of a multiple occurrence of a species in a plot, for instance.


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


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


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


A data frame including a cross table.


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


Character vector indicating no records in the cross table.


An object of class data.frame.


Miguel Alvarez


veg <- subset(Kenya_veg, REFERENCE == 2331, slot = "header")

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

## cross table of the first 5 plots
Cross <- crosstable(cover_perc ~ ReleveID + AcceptedName + AuthorName,
  veg[1:5, ], mean,
  na_to_zero = TRUE
#>               AcceptedName                AuthorName 1940 1937 1938 1939 1941
#> 1      Commiphora africana          (A. Rich.) Engl.  0.5    0    0    0  0.0
#> 2     Eragrostis macilenta         (A. Rich.) Steud.  3.0    3    3    3  0.0
#> 3       Helinus mystacinus (Aiton) E. Mey. ex Steud.  0.0    0    0    0  3.0
#> 4   Eragrostis cilianensis        (All.) F. T. Hubb.  3.0    3    3    3  3.0
#> 5 Astripomoea lachnosperma        (Choisy) A. Meeuse  3.0    3    0    3  3.0
#> 6       Coccinia trilobata        (Cogn.) C. Jeffrey  3.0    0    3    3  0.5