0

I need to convert my OTU table from my phyloseq object into a data frame so that I can use it to run PICRUSt2, but as.data.frame(physeq@otu_table) won't make it a data frame. I tried pie<-as.matrix(physeq@otu_table) and when I say is.matrix(pie) #it says TRUE, but when I say class(pie) #it says [1] "otu_table" attr(,"package") [1] "phyloseq" It wont even pretend to be a data frame:

pie<-as.data.frame(physeq@otu_table)
is.data.frame(pie)
#FALSE

I can't just use my asv_mat from before I put it into the phyloseq object because I had to remove mitochondria and chloroplast from my phyloseq object. This will still be in asv_mat.

Thanks in advance

brynaR
  • 11
  • 5
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 09 '21 at 08:00

2 Answers2

1
pie<-as.matrix(physeq@otu_table)
pie<-as.data.frame(pie)

making it a matrix, then saving as a dataframe and remembering to save over the original matrix as a data frame (i.e. pie<-as.data.frame(pie) rather than just as.data.frame(pie)) worked.

brynaR
  • 11
  • 5
-1

Sorry I don't have enough information to properly help you, but have you ever tried to use as_tibble() from the tidyverse package, instead of as_dataframe() ?

Erich Zann
  • 44
  • 3