R -- 數(shù)據(jù)分析,表格制作,excel, table
2022-03-06 13:27 作者:六月忘了看太陽(yáng) | 我要投稿

data(“PlantGrowth”)??數(shù)據(jù)
第一步:生成分類變量
PG= PlantGrowth%>%
mutate(weight_cat=case_when(
??weight<=4.5~”light”,
??weight>4.5&weight<=5.5~”medium”,
??weight>5.5~”heavy”
??))
第二步:制表
tab_count1=table(PG$group,PG$weight_cat)
第三步:增加表總數(shù)的行列
tab_count2=addmargins(tab_count1,1) 1為行,2為列
第四步:生成百分比
tab_per1=prop.table(tab_count2,1)*100
tab_count3=addmargins(tab_per1,2
tab_per2=addmargins(tab_per1,2)
第五步:將tab_count3與tab_per2合成一個(gè)表格
tab_combine=matrix(
??pasteq(tab_count3,”(“,round(tab_per2,2),”%”),
??dim(tab_count3),
??dimnames=dimnames(tab_count3)
??)
標(biāo)簽: