根据布尔值分析分类数据
Analyse categorical data against boolean
我在 R 中有一个数据框,其中包含以下数据
> df3
care_uncare risks
1 No High risk patients
2 Yes High risk patients
3 Yes High risk patients
4 Yes High risk patients
5 Yes Low risk patients
6 Yes Low risk patients
7 No Low risk patients
8 Yes High risk patients
9 Yes Low risk patients
10 Yes Low risk patients
11 Yes High risk patients
12 Yes Low risk patients
13 No Low risk patients
14 Yes Low risk patients
15 Yes Low risk patients
16 Yes High risk patients
其中 care_uncare 变量包含 Yes/No 值,风险变量包含高风险 patients/Low 风险患者。
我想生成一个摘要或可视化,显示 care_uncare 为 'Yes' 但有风险为 'High risk patients'
的患者总数
我该如何进行分析?
这可以很容易地用这个:
df3 %>% group_by(care_uncare, risks) %>% summarise( n = n() )
您可以使用 filter
和 summarise
library(dplyr)
df %>% filter(care_uncare == "Yes" & risks == "High risk patients") %>%
summarise( Total_Yes_High = n() )
a care_uncare risks
<chr> <chr> <chr>
1 2 Yes High risk patients
2 3 Yes High risk patients
3 4 Yes High risk patients
4 8 Yes High risk patients
5 11 Yes High risk patients
6 16 Yes High risk patients
我在 R 中有一个数据框,其中包含以下数据
> df3
care_uncare risks
1 No High risk patients
2 Yes High risk patients
3 Yes High risk patients
4 Yes High risk patients
5 Yes Low risk patients
6 Yes Low risk patients
7 No Low risk patients
8 Yes High risk patients
9 Yes Low risk patients
10 Yes Low risk patients
11 Yes High risk patients
12 Yes Low risk patients
13 No Low risk patients
14 Yes Low risk patients
15 Yes Low risk patients
16 Yes High risk patients
其中 care_uncare 变量包含 Yes/No 值,风险变量包含高风险 patients/Low 风险患者。
我想生成一个摘要或可视化,显示 care_uncare 为 'Yes' 但有风险为 'High risk patients'
的患者总数我该如何进行分析?
这可以很容易地用这个:
df3 %>% group_by(care_uncare, risks) %>% summarise( n = n() )
您可以使用 filter
和 summarise
library(dplyr)
df %>% filter(care_uncare == "Yes" & risks == "High risk patients") %>%
summarise( Total_Yes_High = n() )
a care_uncare risks
<chr> <chr> <chr>
1 2 Yes High risk patients
2 3 Yes High risk patients
3 4 Yes High risk patients
4 8 Yes High risk patients
5 11 Yes High risk patients
6 16 Yes High risk patients