The following function is adapted from HTSSIP R package phyloseq data object conversion to data.frame
Useful links