首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在R-微生物群上对流行人群进行性别细分

如何在R-微生物群上对流行人群进行性别细分
EN

Stack Overflow用户
提问于 2020-02-29 23:38:59
回答 1查看 43关注 0票数 0

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

代码语言:javascript
复制
# 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")

对于如何在这里进行性别划分,有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2020-03-09 12:00:58

如果您想创建单独的phyloseq对象,例如包含high组和females.you,可以使用subset_samples

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60466768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档