如何为此列联表的每一行获取where 4 or more
的频率分布和百分比?
> table(People$Gender, People$BooksOwned)
-1 3 4 5 6 8 10 12
0 0 1 125 7 170 73 1 2
1 2 0 11 0 20 14 1 1
我不知道如何在各行上调用函数。
答案 0 :(得分:0)
那是easy:
> gender_books <- table(People$Gender, People$BooksOwned)
> prop.table(gender_books, 1) # row percentages, column is 2
0 0.000000000 0.002638522 0.329815303 0.018469657 0.448548813 0.192612137 0.002638522 0.005277045
1 0.040816327 0.000000000 0.224489796 0.000000000 0.408163265 0.285714286 0.020408163 0.020408163
gender_books_percents <- prop.table(gender_books, 1)
rowSums(gender_books_percents[,c('4', '6', '8', '10', '12')], na.rm=TRUE)
0 1
0.6490765 0.7346939