Skip to contents

Convert a flat data.frame with species occurrence/abundance at site level into a proper data.frame object that can then be used by other functions. The final output contains sites in rows and species in columns.

Usage

fb_format_site_species(data, site, species, value, na_to_zero = TRUE)

Arguments

data

a data.frame in a long format (see example).

site

a character of length 1. Name of the column with site labels.

species

a character of length 1. Name of the column with species names.

value

a character of length 1. Name of the column with species occurrence/abundance.

na_to_zero

a logical value. If TRUE (default) NA are replaced by 0.

Value

A data.frame with sites in rows and species in columns. The first column is named "site" and contains the name of the sites.

Examples

library("funbiogeo")

filename <- system.file("extdata", "raw_mammals_data.csv", 
                        package = "funbiogeo")
all_data <- read.csv(filename)

head(all_data)
#>   species           order    site longitude latitude count adult_body_mass
#> 1  sp_001 Cetartiodactyla  fb_103  7.271821 59.09736     1        461900.8
#> 2  sp_001 Cetartiodactyla fb_1001 20.771821 52.59736     1        461900.8
#> 3  sp_001 Cetartiodactyla  fb_102  6.771821 59.09736     1        461900.8
#> 4  sp_001 Cetartiodactyla  fb_104  7.771821 59.09736     1        461900.8
#> 5  sp_001 Cetartiodactyla  fb_101  6.271821 59.09736     1        461900.8
#> 6  sp_001 Cetartiodactyla fb_1000 20.271821 52.59736     1        461900.8
#>   gestation_length litter_size max_longevity sexual_maturity_age diet_breadth
#> 1              235        1.25           324               668.2            1
#> 2              235        1.25           324               668.2            1
#> 3              235        1.25           324               668.2            1
#> 4              235        1.25           324               668.2            1
#> 5              235        1.25           324               668.2            1
#> 6              235        1.25           324               668.2            1

site_species <- fb_format_site_species(all_data, "site", "species", "count")
site_species[1:3, 1:4]
#>      site sp_001 sp_002 sp_005
#> 1  fb_103      1      0      0
#> 2 fb_1001      1      1      1
#> 3  fb_102      1      0      0