我正在尝试处理数据,并希望基于两类都具有分类级别的列创建新变量。我试图用tidyverse通过3种方式实现这一点(需要坚持使用该库)。
这是我尝试过的。
a_method
但是,我遇到了一个错误:
LibraryClass
第二,我也尝试在tidyverse中使用unite函数,但没有成功。
最后,第三,我在同一库中搜索并找到了组索引。这是我所做的,但失败了。 :)
this.usersService.getUsers().subscribe(users => {
this.users = users.sort((x,y) => x.? - y.?);
});
有错误:
data_indices <- df_subs %>%
mutate(ifelse(sex == "Female" & patient.class == "Not_Admitted", "female_not_admitted",
ifelse(sex == "Female" & patient.class == "ORDINARY ADMISSION", "female_admitted",
ifelse(sex == "Male" & patient.class == "Not_Admitted", "male_not_admitted",
ifelse(sex == "Male" & patient.class == "ORDINARY ADMISSION", "male_admitted")))))
有人可以帮忙吗?
答案 0 :(得分:3)
有点难以理解您需要执行的功能。但这是一个猜测:)
df_subs <- data.frame(sex = c("Male",
"Female",
"Female"),
patient.class = c("Not_Admitted",
"ORDINARY ADMISSION",
"ORDINARY ADMISSION"))
# Question 1
df_subs %>%
mutate(sex_patient_class = case_when(
sex == "Female" & patient.class == "Not_Admitted" ~ "female_not_admitted",
sex == "Female" & patient.class == "ORDINARY ADMISSION" ~ "female_admitted",
sex == "Male" & patient.class == "Not_Admitted" ~ "male_not_admitted",
sex == "Male" & patient.class == "ORDINARY ADMISSION" ~ "male_admitted"
))
# Question 2
df_subs %>%
unite(sex_patient_class, sex, patient.class, sep = "_")
# Question 3
df_subs %>%
mutate(group_indices = group_indices(., patient.class, sex))