简体   繁体   中英

Join table() together in R

So ive been stuck with a problem in order to show the frecuencies of my groups across some data where i have multiple NA's.

Here its an example, i have dropped the Na's with the function drop_na, so they are "irrelevant" if i already got the tables.

df_1= data.frame(Group=c("Control","Control","Case A","Case B", "Case C"), c(1,2,3,4,5))
table(df_1$Group)

在此处输入图像描述

df_2= data.frame(Group=c("Control","Case A","Case A","Case B", "Case D"), c(1,2,3,4,5))
table(df_2$Group)

在此处输入图像描述

How could i join them in 1?, preferably with a column indicating its origin as "table1" or something.

Like this?

tab <- rbind(table(df_1$Group),table(df_2$Group))
rownames(tab) <- c("table 1", "table 2")
tab

        Case A Case B Case C Control
table 1      1      1      1       2
table 2      2      1      1       1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM