Skip to content

Community data matrix to tidy tibbles and vice versa

Notifications You must be signed in to change notification settings

fkeck/flexitarian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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")

About

Community data matrix to tidy tibbles and vice versa

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages