Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 946 Bytes

README.md

File metadata and controls

45 lines (32 loc) · 946 Bytes

flexitarian

For those who want to combine tidyverse with functions that require community data matrices stored in dataframes.

Installation

You can install flexitarian from GitHub with the devtools package:

devtools::install_github("fkeck/flexitarian")  

Tibbles to dataframes (and vice versa)

Example

library(flexitarian)
x <- data.frame(matrix(rpois(100, 10), nrow = 10))
rownames(x) <- paste("Site", 1:10)
colnames(x) <- paste("Species", LETTERS[1:10])
x
x_tidy <- tidy_cdm(x)
x_tidy
x_df <- spread_cdm(x_tidy, SITE, TAXON, COUNT)
x_df
x_df <- spread_cdm(x_tidy, SITE, TAXON, COUNT, keep.order = TRUE)
all.equal(x, x_df)
x_tidy %>% 
    spread_cdm(SITE, TAXON, COUNT) %>% 
    vegan::diversity() %>% 
    enframe("SITE", "SHANNON_IDX")