【问题标题】:How to subdivide prevalence groups into gender on R - microbiome如何在 R 上将患病人群细分为性别 - 微生物组
【发布时间】:2020-02-29 15:38:59
【问题描述】:

我是 R 新手。我正在使用一个脚本,该脚本根据国家/地区将 atlas1006 微生物组数据分成 3 组疾病流行率(低、中、高)。我想将每组细分:低、中、高,每组分为男性和女性,即低男性、低女性、中男性、中女性、高男性、高女性。我也想保持现有的 3 个组低、中、高。 这是将数据分成低、中、高的代码:

# Create mnd variable
# grabs the nationality from phyloseq
test <- get_variable(pseq, "nationality" )

# check you've installed this library
library(forcats)

# this collapses the two variables into a new variable AB in this case. The command for multiple changes is fct_collapse(x, AB = c("A","B"), DE = c("D","E"))
# test <- fct_collapse(test, LOW = c("Scandinavia","EasternEurope") , MEDIUM = c("SouthEurope","CentralEurope", "UKIE"), HIGH = c("US") )

test <- fct_collapse(test, LOW = c("EasternEurope","Scandinavia") , MEDIUM = c("SouthEurope","CentralEurope", "UKIE" ), HIGH = c("US"))

# reorder
test <- factor(test, levels = (c("LOW", "MEDIUM", "HIGH")))
levels(test)

# creates a new variable in the phyloseq called mnd
sample_data(pseq)$mnd = test

# checks that it has worked.
get_variable(pseq, "mnd")

关于如何从这里进行性别分割的任何想法?

【问题讨论】:

    标签: r phyloseq


    【解决方案1】:

    如果您想创建包含高组和女性的单独 phyloseq 对象。您可以使用 subset_samples

    subset_samples(pseq, mnd=="high" &amp; gender_variable == "female")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-05
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      相关资源
      最近更新 更多