Académique Documents
Professionnel Documents
Culture Documents
Homework #1
2.
a) > seq(1,10,2)
[1] 1 3 5 7 9
Make a vector of sequential values from 1 to 10 in steps of 2.
b) > seq(1,5)-0.5
[1] 0.5 1.5 2.5 3.5 4.5
Make a vector of sequential values from 1 to 5 and subtracting 0.5 to each element of the vector.
c) > trials=rbinom(30,10,0.3)
> trials
[1] 3 4 2 4 3 1 1 5 1 2 4 2 3 4 3 5 2 2 3 3 6 3 5 1 6 2 0 1 3 3
> hist(trials)
d) > my.breaks=seq(0,11)-0.5
> hist(trials,breaks=my.breaks)
moral
hetero
mobilit
region
y
Rochester
Syracuse
Worcester
Erie
Milwaukee
Bridgeport
Buffalo
Dayton
Reading
Des_Moines
Cleveland
Denver
Peoria
Wichita
Trenton
Grand_Rapids
Toledo
San_Diego
Baltimore
South_Bend
Akron
Detroit
Tacoma
Flint
Spokane
Seattle
Indianapolis
Columbus
Portland_Orego
n
Richmond
Houston
Fort_Worth
Oklahoma_City
Chattanooga
Nashville
Birmingham
Dallas
Louisville
Jacksonville
Memphis
19
17
16.4
16.2
15.8
15.3
15.2
14.3
14.2
14.1
14
13.9
13.8
13.6
13
12.8
12.7
12.5
12
11.8
11.3
11.1
10.9
9.8
9.6
9
8.8
8
20.6
15.6
22.1
14
17.4
27.9
22.3
23.7
10.6
12.7
39.7
13
10.7
11.9
32.5
15.7
19.2
15.9
45.8
17.9
20.4
38.3
17.8
19.3
12.3
23.9
29.2
27.4
15
20.2
13.6
14.8
17.6
17.5
14.7
23.8
19.4
31.9
18.6
34.5
35.1
42.7
15.8
24.2
21.6
49.8
12.1
27.4
22.1
19.5
31.2
32.2
38.9
34.2
23.1
25
E
E
E
E
MW
E
E
MW
E
MW
MW
W
MW
MW
E
MW
MW
W
E
MW
MW
MW
W
MW
W
W
MW
MW
7.2
10.4
10.2
10.2
9.7
9.3
8.6
8.2
8
7.7
6
5.4
16.4
65.3
49
30.5
20.7
57.7
57.4
83.1
36.8
31.5
73.7
84.5
35.8
24.9
36.1
36.8
47.2
27.2
25.4
25.9
37.8
19.4
27.7
26.7
W
S
S
S
S
S
S
S
S
S
S
S
Tulsa
Miami
Atlanta
5.3
5.1
4.2
23.8
50.2
70.6
44.9 S
41.8 S
32.6 S
> head(Angell)
Rochester
Syracuse
Worcester
Erie
Milwauke
e
Bridgeport
mobilit
moral
hetero
y
19
20.6
15
17
15.6
20.2
16.4
22.1
13.6
16.2
14
14.8
15.8
15.3
17.4
27.9
b) > plot(Angell$hetero,Angell$moral)
region
E
E
E
E
17.6 MW
17.5 E
> plot(Angell$moral~Angell$hetero)
4.
a) > getwd()
[1] "C:/Users/Carlos/Documents"
b) > write.csv(Angell,"Angell_data.csv")
c) > read.csv("C:/Users/Carlos/Documents/Angell_data.csv",header=TRUE)