How to extract to columns from a phyloseq sample_data object?
1
1
Entering edit mode
4.4 years ago
dpc ▴ 250

Hi I have converted my data into phyloseq object for statistical analysis. From the sample_data object I want to select two specific columns which I will further combine with a distance matrix. But, I am unable to extract out those two columns. I am using these codes which is reversing the following error:

My code:

sd = as.matrix(sample_data(physeq))
sd = sd %>%
  select("SampleID", "type") %>%
  mutate_if(is.factor,as.character)

Error reversed:

Error in UseMethod("select_") : 
  no applicable method for 'select_' applied to an object of class "c('matrix', 'array', 'character')"

How should I do the step?

Thanks dpc

phyloseq • 6.1k views
ADD COMMENT
0
Entering edit mode

try.

sample_data(physeq) %>%
    data.frame() %>%
    select("SampleID", "type") %>%
    mutate_if(is.factor,as.character)
ADD REPLY
1
Entering edit mode
4.4 years ago

Hi,

The problem is that pipes, as far as I know, only works with tibble data frames or data frames. Therefore you should coerce your sample metadata from phyloseq class into a data frame class, by doing:

sd = data.frame(sample_data(physeq))

I hope this solves your problem,

António

ADD COMMENT

Login before adding your answer.

Traffic: 1890 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6