Search code examples
rdataframematrixphyloseq

OTU table from phyloseq object can't be coerced into a data frame


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


Solution

  • 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.