In: Statistics and Probability
Q. Make a vector of weights in order from the youngest person to the oldest.
What is the code here? I should get a code in R program.
firstName | gender | age | height | weight | bmi | overWt | ||
1 | Tom | m | 77 | 70 | 175 | 25.16238799 | TRUE | |
2 | May | f | 33 | 64 | 125 | 21.50106395 | FALSE | |
3 | Joe | m | 79 | 73 | 185 | 24.45884214 | FALSE | |
4 | Bob | m | 47 | 67 | 156 | 24.4841414 | FALSE | |
5 | Sue | f | 27 | 64 | 105 | 18.06089372 | FALSE | |
6 | Liz | f | 33 | 68 | 190 | 28.94980625 | TRUE | |
7 | Jon | m | 67 | 68 | 185 | 28.18796924 | TRUE | |
8 | Sal | f | 52 | 65 | 124 | 20.67782511 | FALSE | |
9 | Tim | m | 59 | 68 | 175 | 26.66429523 | TRUE | |
10 | Tom | m | 27 | 71 | 215 | 30.04911241 | TRUE | |
11 | Ann | f | 55 | 67 | 166 | 26.05363764 | TRUE | |
12 | Dan | m | 24 | 66 | 140 | 22.64383859 | FALSE | |
13 | Art | m | 46 | 66 | 150 | 24.26125563 | FALSE | |
14 | Zoe | f | 48 | 62 | 125 | 22.91060301 | FALSE | |
R codes and output:
> data=read.table('weight.csv',header=TRUE, sep=',')
> head(data)
firstName gender age height weight bmi overWt
1 Tom m 77 70 175 25.16239 TRUE
2 May f 33 64 125 21.50106 FALSE
3 Joe m 79 73 185 24.45884 FALSE
4 Bob m 47 67 156 24.48414 FALSE
5 Sue f 27 64 105 18.06089 FALSE
6 Liz f 33 68 190 28.94981 TRUE
> attach(data)
> data_1=data[order(age),] # this command sort data in ascending
order by age
> data_1
firstName gender age height weight bmi overWt
12 Dan m 24 66 140 22.64384 FALSE
5 Sue f 27 64 105 18.06089 FALSE
10 Tom m 27 71 215 30.04911 TRUE
2 May f 33 64 125 21.50106 FALSE
6 Liz f 33 68 190 28.94981 TRUE
13 Art m 46 66 150 24.26126 FALSE
4 Bob m 47 67 156 24.48414 FALSE
14 Zoe f 48 62 125 22.91060 FALSE
8 Sal f 52 65 124 20.67783 FALSE
11 Ann f 55 67 166 26.05364 TRUE
9 Tim m 59 68 175 26.66430 TRUE
7 Jon m 67 68 185 28.18797 TRUE
1 Tom m 77 70 175 25.16239 TRUE
3 Joe m 79 73 185 24.45884 FALSE