这是我的代码:
## Extract different phecode class
#1 Subset for circulatory system
circulatory_system <- per_class %>% filter(exclude_name == "circulatory system")
#2 Subset for dermatologic
dermatologic <- per_class %>% filter(exclude_name == "dermatologic")
#3 Subset for endocrine/metabolic
endocrine_metabolic <- per_class %>% filter(exclude_name == "endocrine/metabolic")
#4 Subset for genitourinary
genitourinary <- per_class %>% filter(exclude_name == "genitourinary")
#5 Subset for infectious diseases
infectious_diseases <- per_class %>% filter(exclude_name == "infectious diseases")
## List all phecode class
data_list <- list(
circulatory_system = list(df = circulatory_system, exclude_name = "circulatory system"),
dermatologic = list(df = dermatologic, exclude_name = "dermatologic"),
endocrine_metabolic = list(df = endocrine_metabolic, exclude_name = "endocrine/metabolic"),
genitourinary = list(df = genitourinary, exclude_name = "genitourinary"),
infectious_diseases = list(df = infectious_diseases, exclude_name = "infectious diseases"),
)
我想问一下,是否有更简化的方法来制作相同格式的data_list?因为我的phecode类有15个以上,所以看起来很乱。
谢谢大家。
2条答案
按热度按时间f8rj6qna1#
有多种方法可以实现这一点,但如果您可以控制
data_list
所使用的实际数据结构,我建议使用tidyr::nest()
,因为它更简洁。tidyr::nest()
的输出将是一个包含两列的tibble,一列是“拉出”的列(在本例中为exclude_name),df是包含过滤后的 Dataframe 的列表列(减去拉出的列)。下面是使用
iris
数据集和Species
列的所有三个选项的示例。创建于2023-04-30使用reprex v2.0.2
46qrfjad2#
考虑base R的
by
(tapply
的面向对象 Package 器),它返回一个用于单因子拆分的特殊命名列表:要调整下划线的空格和特殊字符的名称,请执行以下操作: