[问题类型]:程式咨询
用R做枢纽分析的表格
[熟悉程度]
入门(写过一点点程式,对语法不熟悉)
[问题叙述]:
以下是我的资料
group sex olds
1 A 2 0-20
2 A 2 0-20
3 A 2 0-20
4 A 2 0-20
5 A 1 0-20
6 A 2 0-20
7 A 2 0-20
8 A 2 0-20
9 A 1 0-20
10 A 1 0-20
11 A 1 21-60
12 A 2 21-60
13 A 2 21-60
14 A 1 21-60
15 A 2 21-60
16 B 1 21-60
17 B 1 21-60
18 B 1 21-60
19 B 2 21-60
20 B 2 21-60
21 B 1 61-100
22 B 1 61-100
23 B 1 61-100
24 B 2 61-100
25 B 1 61-100
26 B 1 61-100
27 B 1 61-100
28 B 1 61-100
29 B 1 61-100
30 B 2 61-100
想将资料转成性别(sex)比例的分布
大概会是这样
group_A group_B
0-20 0.68 0.53
21-60 0.11 0.22
61-100 0.21 0.25
小计 1 1
[目前程式码]:
https://ideone.com/fork/c3ippk
[环境]
R R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] dplyr_0.8.0.1 lubridate_1.7.4 ggplot2_3.1.0
[4] lattice_0.20-38
[关键字]: