Practical 10

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

1

2 Exercise 1
3
4
5 1. 67+78-45
6 2. 43+52 -3x81
47
3. √ 28+ √ 547− 53
3
7

8 4. e +12% of 75
3

9 5. ∛729+log(23/42)
10 6. (1.01)6+(2.67)3.4 – (3.2)(-2.1)
11 7. 233 +4562 -56.
12
13
14
15 1.67+78-45
16 [1] 100
17 2.> 4^3+5^2-3*81
18 [1] -154
19 3.> sqrt(28)+547^(1/3)-(47/53)
20 [1] 12.583
21 4.> exp(3)+0.12*75
22 [1] 29.08554
23 5.> 729^(1/3)+log(23/42)
24 [1] 8.397825
25 6.> (1.01)^6+(2.67)^(3.4)-(32)^(-2.1)
26 [1] 29.25363
27 7.> 23^3+456^2-56
28 [1] 22004

29

30 > Exercise 2
31 1. Assign single values to X and Y as 3 and 4. Then find Z = X + Y; W = X*Y;
32 A = Z + W; B = A2 +√ Y; C= X3+Y3
33
34
35 >x=3
36 >y=4
37 > z=x+y
38 >z
39 [1] 7
40 > w=x*y
41 >w
42 [1] 12
43 > a=z+w
44 >a
45 [1] 19
46 > b=a^2+sqrt(y)
47 >b
48 [1] 363
49 > c=x^3+y^3
50 >c
51 [1] 91
52

53 2.> Assign combination of values (equal length) to X and Y and do above


54 calculations. for eg X= [2, 3, 5, 7] and Y= [11,13,17,19]
55
56 > x=c(2,3,5,7);y=c(11,13,17,19)
57 > z=x+y
58 >z
59 [1] 13 16 22 26
60 > w=x*y
61 >w
62 [1] 22 39 85 133
63 > a=z+w
64 >a
65 [1] 35 55 107 159
66 > b=a^2+sqrt(y)
67 >b
68 [1] 1228.317 3028.606 11453.123 25285.359
69 > c=x^3+y^3
70 >c
71 [1] 1339 2224 5038 7202

72

73 3 For problem 2 obtain the values for X/2, Y/3, X/Y


74
75 > x/2
76 [1] 1.0 1.5 2.5 3.5
77 > y/3
78 [1] 3.666667 4.333333 5.666667 6.333333
79 > x/y
80 [1] 0.1818182 0.2307692 0.2941176 0.3684211

81

82 4.Assign a vector of character strings (“Bob”, “Jack”, “Jill”) for names.


83
84 > names=c("Bob","Jack","Jill")
85 > names
86 [1] "Bob" "Jack" "Jill"

87

88 Exercise 3

89 Q1. Use sequence operator to get a sequence


90 i. from 1 to 20
91 ii. from 20 to 10
92 iii. From 2 to 30 of width 2
93 > 1:20
94 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
95 > 20:10
96 [1] 20 19 18 17 16 15 14 13 12 11 10
97 > 2*1:15
98 [1] 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30

99
100 Q2 Assign value 15 to n and find the difference between 1: n-1 and 1:(n-1)
101
102
103 > n=15
104 > 1:n-1
105 [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
106 > 1:(n-1)
107 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14

108

109 Exercise 4

110 Q1. Enter the following data using rep function


111 1. 1,1,1,1,2,2,3,3,3,3,3,
112 2. 4,4,4,4,5,5,6,6,6,6,7,8,8,8
113 3. 1,1,2,2,3,3,4,4,5,5,6,6
114 4. 10,10,10,10,11,11,11,11,12,12,12,12
115
116
117
118 a=c(rep(1,4),rep(2,2),rep(3,5))
119 >a
120 [1] 1 1 1 1 2 2 3 3 3 3 3
121 > b=c(rep(4,4),rep(5,2),rep(6,4),7,rep(8,3))
122 >b
123 [1] 4 4 4 4 5 5 6 6 6 6 7 8 8 8
124 > c=rep(1:6,each=2)
125 >c
126 [1] 1 1 2 2 3 3 4 4 5 5 6 6
127 > d=rep(10:12,each=4)
128 >d
129 [1] 10 10 10 10 11 11 11 11 12 12 12 12

130

131 > Exercise 5


132 Q1 Using data.frame function make the following frequency distribution.
1. Age freq 2. Marks freq 3. Variable freq
11 5 15 2 13 1
12 10 20 2 17 1
13 120 25 3 19 2
14 22 30 3 24 2
15 13 35 3 29 3
16 5 40 4 33 3
133
134
135
136 age=11:16
137 > freq=c(5,10,120,22,13,5)
138 > d1=data.frame(age,freq)
139 > d1
140 age freq
141 1 11 5
142 2 12 10
143 3 13 120
144 4 14 22
145 5 15 13
146 6 16 5
147 >
148 > marks=c(15,20,25,30,35,40)
149 > freq=c(2,2,3,3,3,4)
150 > d2=data.frame(marks,freq)
151 > d2
152 marks freq
153 1 15 2
154 2 20 2
155 3 25 3
156 4 30 3
157 5 35 3
158 6 40 4
159 >
160 > variable=c(13,17,19,24,29,33)
161 > freq=c(1,1,2,2,3,3)
162 > d3=data.frame(variables,freq)
163 Error: object 'variables' not found
164 > d3=data.frame(variable,freq)
165 > d3
166 variable freq
167 1 13 1
168 2 17 1
169 3 19 2
170 4 24 2
171 5 29 3
172 6 33 3

173

174 Q2 For the above data change the names of the columns
175 1. Mid age and No of cases.
176 2. Score and No of students
177 3. Income in ‘000 and No of families
178 > colnames(d1)=c("mid age","no of cases")
179 > d1
180 mid age no of cases
181 1 11 5
182 2 12 10
183 3 13 120
184 4 14 22
185 5 15 13
186 6 16 5

187
188 > colnames(d2)=c("score","no of students")
189 > d2
190 score no of students
191 1 15 2
192 2 20 2
193 3 25 3
194 4 30 3
195 5 35 3
196 6 40 4
197 >
198 > colnames(d3)=c("income","no of familes")
199 > d3
200 income no of familes
201 1 13 1
202 2 17 1
203 3 19 2
204 4 24 2
205 5 29 3
206 6 33 3

207 Exercise 6

208 Following is the data set: 5, 12, 21, 25, 25, 30, 25, 40, 42, 38, 50, 45, 60, 65,
209 50,70, 80, 50,13. Use the built-in functions discussed above, on the data set x.
210
211 x=scan()
212 1: 5 12 21 25 25 30 25 40 42 38 50 45 60 65 50 70 80 50 13
213 20:
214 Read 19 items
215 > length(x)
216 [1] 19
217 > max(x
218 [1] 80
219 > min(x)
220 [1] 5
221 > range(x)
222 [1] 5 80
223 >
224 > Exercise 7
225 Q For the given data sets;
226 i) Enter the data set either using the scan function or c function .
227 ii) Find the index for its maximum and minimum value
228 iii) Find the summary.
229 iv) Find all functions wrt this data set
230 v) Construct the discrete distribution.
231
232 Data set I: 13, 17, 24, 21, 28, 28, 13, 27, 17, 23, 17, 24, 21, 17, 23, 21
233
234
235 > x=c(13,17,24,21,28,28,13,27,17,23,21)

236
237 [1] 28
238 > min(x)
239 [1] 13
240 > summary(x)
241 Min. 1st Qu. Median Mean 3rd Qu. Max.
242 13.00 17.00 21.00 20.88 24.00 28.00
243 > names(x)
244 NULL
245 > quantile(x,probs=seq(0,1,.1))
246 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
247 13.0 15.0 17.0 17.0 21.0 21.0 23.0 23.5 24.0 27.5 28.0
248 > quantile(x,c(0.76,0.78))
249 76% 78%
250 24 24
251 > table(x)
252 x
253 13 17 21 23 24 27 28
254 2 4 3 2 2 1 2
255 > t=table(x)
256 >t
257 x
258 13 17 21 23 24 27 28
259 2 4 3 2 2 1 2
260 > names(t)[t==max(t)]
261 [1] "17"
262 > length(x)
263 [1] 16
264 > range(x)
265 [1] 13 28
266 > quantile(x)
267 0% 25% 50% 75% 100%
268 13 17 21 24 28
269 > IQR(x)
270 [1] 7
271 > sum(x)
272 [1] 334
273 > cumsum(x)
274 [1] 13 30 54 75 103 131 144 171 188 211 228 252 273 290 313 334
275 > mean(x)
276 [1] 20.875
277 > var(x)
278 [1] 23.45
279 > sort(x)
280 [1] 13 13 17 17 17 17 21 21 21 23 23 24 24 27 28 28
281 > median(x)
282 [1] 21

283

284 Data set II: 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 4, 5, 5, 4, 4, 3, 3, 3, 3, 2, 2, 2, 3, 2, 3, 2, 2,


285 2, 1, 1, 1, 0, 0, 1, 0, 3, 3, 2, 2, 2, 3, 2, 3, 2, 2, 2, 1, 1, 1, 0, 0, 1, 0
286
287 x=c(0,1,2,3,4,5,6,6,5,4,4,5,5,4,4,3,3,3,3,2,2,2,3,2,3,2,2,2,1,1,1,0,0,1,0,3,3,2,2,2,3,2,2,2,1,1,1,0,0,1,0)
288 > length(x)
289 [1] 51
290 > max(x)
291 [1] 6
292 > min(x)
293 [1] 0
294 > range(x)
295 [1] 0 6
296 > quantile(x)
297 0% 25% 50% 75% 100%
298 0 1 2 3 6
299 > IQR(x)
300 [1] 2
301 > sum(x)
302 [1] 119
303 > cumsum(x)
304 [1] 0 1 3 6 10 15 21 27 32 36 40 45 50 54 58 61 64 67 70 72 74
305 [22] 76 79 81 84 86 88 90 91 92 93 93 93 94 94 97 100 102 104 106 109 111
306 [43] 113 115 116 117 118 118 118 119 119
307 > mean(x)
308 [1] 2.333333
309 > median(x)
310 [1] 2
311 > var(x)
312 [1] 2.586667
313 > sort(x)
314 [1] 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4
315 [43] 4 4 4 5 5 5 5 6 6
316 > names(x)
317 NULL
318 > summary(x)
319 Min. 1st Qu. Median Mean 3rd Qu. Max.
320 0.000 1.000 2.000 2.333 3.000 6.000
321 > table(x)
322 x
323 0 1 2 3 4 5 6
324 7 9 14 10 5 4 2
325 > names(t)[t==max(t)]
326 [1] "17"

327 Exercise 8

328 Prepare a continuous frequency distribution for the given question


329 Q1. A psychologist estimates the I.Q. of 60 children. The values are as
330 follows :103, 98, 87, 85, 67, 96, 115, 109, 127, 103, 95, 123, 94, 88,
331 102, 76, 73, 80, 84, 102, 115, 93, 76, 81, 132, 90, 119, 84, 97, 120, 114,
332 101, 153, 98, 99, 105, 110, 107, 110, 128, 89, 112, 118, 101, 122, 146,
333 96, 109, 72, 97, 94, 94, 79, 79, 100, 54, 102, 89, 43, 111.
334

335
336
337 x=c(103, 98, 87, 85, 67, 96, 115, 109, 127, 103, 95, 123, 94, 88, 102, 76, 73, 80, 84, 102, 115, 93, 76,
338 81, 132, 90, 119, 84, 97, 120, 114, 101, 153, 98, 99, 105, 110, 107, 110, 128, 89, 112, 118, 101, 122,
339 146, 96, 109, 72, 97, 94, 94, 79, 79, 100, 54, 102, 89, 43, 111)
340 > summary(x)
341 Min. 1st Qu. Median Mean 3rd Qu. Max.
342 43.00 87.75 98.50 99.10 110.25 153.00
343 > (6-0)/5
344 [1] 1.2
345 > ci=seq(0,154,1.5)
346 > y=cut(x,ci,right=F);

347
348 >y
349 [1] [102,104) [97.5,99) [87,88.5) [84,85.5) [66,67.5) [96,97.5) [114,116) [108,110)
350 [9] [126,128) [102,104) [94.5,96) [123,124) [93,94.5) [87,88.5) [102,104) [75,76.5)
351 [17] [72,73.5) [79.5,81) [84,85.5) [102,104) [114,116) [93,94.5) [75,76.5) [81,82.5)
352 [25] [132,134) [90,91.5) [118,120) [84,85.5) [96,97.5) [120,122) [114,116) [100,102)
353 [33] <NA> [97.5,99) [99,100) [105,106) [110,111) [106,108) [110,111) [128,129)
354 [41] [88.5,90) [111,112) [117,118) [100,102) [122,123) [146,147) [96,97.5) [108,110)
355 [49] [72,73.5) [96,97.5) [93,94.5) [93,94.5) [78,79.5) [78,79.5) [99,100) [54,55.5)
356 [57] [102,104) [88.5,90) [42,43.5) [111,112)
357 102 Levels: [0,1.5) [1.5,3) [3,4.5) [4.5,6) [6,7.5) [7.5,9) [9,10.5) [10.5,12) ... [152,153)
358 >summary(x)
359 y=c(3.7, 3.4, 4.1, 4.0, 3.7, 4.7, 3.3, 2.4, 3.1, 4.2, 3.8, 3.6, 4.2, 4.3, 2.9, 3.6, 3.3, 4.8, 4.0, 3.9, 3.5, 3.5,
360 3.8, 3.8, 4.2, 3.9, 4.9, 3.2, 4.0, 3.8, 3.2, 2.7, 3.4., 3.3, 3.0, 3.1, 3.5, 3.7, 3.9, 4.3, 3.8, 3.7, 3.0, 4.4, 4.1,
361 3.6, 3.7, 3.4, 3.7, 3.3, 3.5, 3.7, 3.0, 2.9, 3.1, 3.3,4.2)
362 Error: unexpected symbol in "y=c(3.7, 3.4, 4.1, 4.0, 3.7, 4.7, 3.3, 2.4, 3.1, 4.2, 3.8, 3.6, 4.2, 4.3, 2.9,
363 3.6, 3.3, 4.8, 4.0, 3.9, 3.5, 3.5, 3.8, 3.8, 4.2, 3.9, 4.9, 3.2, 4.0, 3.8, 3.2, 2.7, 3.4."
364 > y=c(3.7, 3.4, 4.1, 4.0, 3.7, 4.7, 3.3, 2.4, 3.1, 4.2, 3.8, 3.6, 4.2, 4.3, 2.9, 3.6, 3.3, 4.8, 4.0, 3.9, 3.5, 3.5,
365 3.8, 3.8, 4.2, 3.9, 4.9, 3.2, 4.0, 3.8, 3.2, 2.7, 3.4., 3.3, 3.0, 3.1, 3.5, 3.7, 3.9, 4.3, 3.8, 3.7, 3.0, 4.4, 4.1,
366 3.6, 3.7, 3.4, 3.7, 3.3, 3.5, 3.7, 3.0, 2.9, 3.1, 3.3,4.2))
367 Error: unexpected symbol in "y=c(3.7, 3.4, 4.1, 4.0, 3.7, 4.7, 3.3, 2.4, 3.1, 4.2, 3.8, 3.6, 4.2, 4.3, 2.9,
368 3.6, 3.3, 4.8, 4.0, 3.9, 3.5, 3.5, 3.8, 3.8, 4.2, 3.9, 4.9, 3.2, 4.0, 3.8, 3.2, 2.7, 3.4."
369 > summary(x)
370 Min. 1st Qu. Median Mean 3rd Qu. Max.
371 43.00 87.75 98.50 99.10 110.25 153.00
372 > (6-0)/5
373 [1] 1.2
374 > ci=seq(0,154,1)
375 > y=cut(x,ci,right=F);
376 >y
377 [1] [103,104) [98,99) [87,88) [85,86) [67,68) [96,97) [115,116) [109,110)
378 [9] [127,128) [103,104) [95,96) [123,124) [94,95) [88,89) [102,103) [76,77)
379 [17] [73,74) [80,81) [84,85) [102,103) [115,116) [93,94) [76,77) [81,82)
380 [25] [132,133) [90,91) [119,120) [84,85) [97,98) [120,121) [114,115) [101,102)
381 [33] [153,154) [98,99) [99,100) [105,106) [110,111) [107,108) [110,111) [128,129)
382 [41] [89,90) [112,113) [118,119) [101,102) [122,123) [146,147) [96,97) [109,110)
383 [49] [72,73) [97,98) [94,95) [94,95) [79,80) [79,80) [100,101) [54,55)
384 [57] [102,103) [89,90) [43,44) [111,112)
385 154 Levels: [0,1) [1,2) [2,3) [3,4) [4,5) [5,6) [6,7) [7,8) [8,9) [9,10) [10,11) ... [153,154)

386

387 Q2 The following data regarding weight of new born babies is obtained from
388 the office records of a hospital. Weight (kgs.) 3.7, 3.4, 4.1, 4.0, 3.7, 4.7,
389 3.3, 2.4, 3.1, 4.2, 3.8, 3.6, 4.2, 4.3, 2.9, 3.6, 3.3, 4.8, 4.0, 3.9, 3.5, 3.5,
390 3.8, 3.8, 4.2, 3.9, 4.9, 3.2, 4.0, 3.8, 3.2, 2.7, 3.4., 3.3, 3.0, 3.1, 3.5, 3.7,
391 3.9, 4.3, 3.8, 3.7, 3.0, 4.4, 4.1, 3.6, 3.7, 3.4, 3.7, 3.3, 3.5, 3.7, 3.0, 2.9,
392 3.1, 3.3, 4.2.
393
394
395
396 y=c(3.7, 3.4, 4.1, 4.0, 3.7, 4.7, 3.3, 2.4, 3.1, 4.2, 3.8, 3.6, 4.2, 4.3, 2.9, 3.6, 3.3, 4.8, 4.0, 3.9, 3.5, 3.5,
397 3.8, 3.8, 4.2, 3.9, 4.9, 3.2, 4.0, 3.8, 3.2, 2.7, 3.4., 3.3, 3.0, 3.1, 3.5, 3.7, 3.9, 4.3, 3.8, 3.7, 3.0, 4.4, 4.1,
398 3.6, 3.7, 3.4, 3.7, 3.3, 3.5, 3.7, 3.0, 2.9, 3.1, 3.3,4.2)
399 > summary(x)
400 Min. 1st Qu. Median Mean 3rd Qu. Max.
401 43.00 87.75 98.50 99.10 110.25 153.00
402 > (6-0)/5
403 [1] 1.2
404 > ci=seq(0,154,1)
405 > y=cut(x,ci,right=F);
406 >y
407 [1] [103,104) [98,99) [87,88) [85,86) [67,68) [96,97) [115,116) [109,110)
408 [9] [127,128) [103,104) [95,96) [123,124) [94,95) [88,89) [102,103) [76,77)
409 [17] [73,74) [80,81) [84,85) [102,103) [115,116) [93,94) [76,77) [81,82)
410 [25] [132,133) [90,91) [119,120) [84,85) [97,98) [120,121) [114,115) [101,102)
411 [33] [153,154) [98,99) [99,100) [105,106) [110,111) [107,108) [110,111) [128,129)
412 [41] [89,90) [112,113) [118,119) [101,102) [122,123) [146,147) [96,97) [109,110)
413 [49] [72,73) [97,98) [94,95) [94,95) [79,80) [79,80) [100,101) [54,55)
414 [57] [102,103) [89,90) [43,44) [111,112)
415 154 Levels: [0,1) [1,2) [2,3) [3,4) [4,5) [5,6) [6,7) [7,8) [8,9) [9,10) [10,11) ... [153,154)
416 >
417 >exercise 9

418 Exercise 9

419 Q1. access the data set treering containing tree-ring widths in dimensionless
420 unit, from the base package of R. Use R-commands to answer the following
421 i. how many observations are in the data set?
422 ii. What is the minimum and maximum observation?
423 iii. List observation greater than the 1.8.
424 iv. Find the quartiles of the data set.
425 v. Find the index for the maximum and minimum value of data set.
426 vi. Construct appropriate frequency distribution table
427
428
429 length(d)
430 [1] 7980
431 > summary(d)
432 Min. 1st Qu. Median Mean 3rd Qu. Max.
433 0.0000 0.8370 1.0340 0.9968 1.1970 1.9080
434 > d[d>1.8]
435 [1] 1.844 1.850 1.856 1.820 1.884 1.908 1.826 1.802
436 > length(d[d>1.8])
437 [1] 8
438 > d[1:5]
439 [1] 1.345 1.077 1.545 1.319 1.413
440 > quantile(d)
441 0% 25% 50% 75% 100%
442 0.000 0.837 1.034 1.197 1.908
443 > max(d)
444 [1] 1.908
445 > min(d)
446 [1] 0
447 > ci=seq(0,2,0.2)
448 > ci
449 [1] 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
450 > y=cut(d,ci,right=F)
451 > fd=cbind(table(y))
452 > fd
453 [,1]
454 [0,0.2) 121
455 [0.2,0.4) 254
456 [0.4,0.6) 473
457 [0.6,0.8) 914
458 [0.8,1) 1795
459 [1,1.2) 2457
460 [1.2,1.4) 1459
461 [1.4,1.6) 430
462 [1.6,1.8) 69
463 [1.8,2) 8

464

465 Q2 Access the data set rivers, from the base package of R. Use R-commands to
466 answer the following
467 i. how many observations are in the data set?
468 ii. What is the minimum and maximum observation?
469 iii. List observation greater than the median.
470 iv. Find the quartiles of the data set.
471 v. Find the index for the maximum and minimum value of data set.
472 vi. Construct appropriate frequency distribution table
473
474
475 > rivers
476 [1] 735 320 325 392 524 450 1459 135 465 600 330 336 280 315 870 906 202
477 [18] 329 290 1000 600 505 1450 840 1243 890 350 407 286 280 525 720 390 250
478 [35] 327 230 265 850 210 630 260 230 360 730 600 306 390 420 291 710 340
479 [52] 217 281 352 259 250 470 680 570 350 300 560 900 625 332 2348 1171 3710
480 [69] 2315 2533 780 280 410 460 260 255 431 350 760 618 338 981 1306 500 696
481 [86] 605 250 411 1054 735 233 435 490 310 460 383 375 1270 545 445 1885 380
482 [103] 300 380 377 425 276 210 800 420 350 360 538 1100 1205 314 237 610 360
483 [120] 540 1038 424 310 300 444 301 268 620 215 652 900 525 246 360 529 500
484 [137] 720 270 430 671 1770
485 > summary(x)
486 Min. 1st Qu. Median Mean 3rd Qu. Max.
487 43.00 87.75 98.50 99.10 110.25 153.00
488 > x[x>98.50]
489 [1] 103 115 109 127 103 123 102 102 115 132 119 120 114 101 153 99 105 110 107 110 128 112
490 [23] 118 101 122 146 109 100 102 111
491 > quantiles(x)
492 Error in quantiles(x) : could not find function "quantiles"
493 > quantile(x)
494 0% 25% 50% 75% 100%
495 43.00 87.75 98.50 110.25 153.00
496 > max(x)
497 [1] 153
498 > min(x)
499 [1] 43
500 > ci=seq(0,7,100)
501 > ci
502 [1] 0
503 > ci=seq(0,1770,100)
504 > ci
505 [1] 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
506 [18] 1700
507 > y=cut(d,ci,right=F)
508 > fd=cbind(table(y))
509 > fd
510 [,1]
511 [0,100) 7980
512 [100,200) 0
513 [200,300) 0
514 [300,400) 0
515 [400,500) 0
516 [500,600) 0
517 [600,700) 0
518 [700,800) 0
519 [800,900) 0
520 [900,1e+03) 0
521 [1e+03,1.1e+03) 0
522 [1.1e+03,1.2e+03) 0
523 [1.2e+03,1.3e+03) 0
524 [1.3e+03,1.4e+03) 0
525 [1.4e+03,1.5e+03) 0
526 [1.5e+03,1.6e+03) 0
527 [1.6e+03,1.7e+03) 0

528
529 Q3 For the given data
X 0 1 2 3 4
F 6 28 36 25 5
530 a. Add a column of cumulative frequency(cf)
531 b. Add a column of relative frequency(rf) (frequency/total frequency)
532 c. add a column of relative cumulative frequency (cf/total frequency)
533
534 > > x=0:4
535 > f=c(6,28,36,25,5)
536 > d1=data.frame(x,f)
537 > d1
538 x f
539 10 6
540 2 1 28
541 3 2 36
542 4 3 25
543 54 5
544 > cf1=transform(d1,cfreq=cumsum(f))
545 > cf1
546 x f cfreq
547 10 6 6
548 2 1 28 34
549 3 2 36 70
550 4 3 25 95
551 5 4 5 100
552 > cf2=transform(d1,rf=f/sum(f))
553 > cf2
554 x f rf
555 1 0 6 0.06
556 2 1 28 0.28
557 3 2 36 0.36
558 4 3 25 0.25
559 5 4 5 0.05
560 >
561 Q2 Access the data set rivers, from the base package of R. Use R-commands to
562 answer the following
563 i. how many observations are in the data set?
564 ii. What is the minimum and maximum observation?
565 iii. List observation greater than the median.
566 iv. Find the quartiles of the data set.
567 v. Find the index for the maximum and minimum value of data set.
568 vi. Construct appropriate frequency distribution table
569
570
571
572
573 swiss
574 Fertility Agriculture Examination Education Catholic Infant.Mortality
575 Courtelary 80.2 17.0 15 12 9.96 22.2
576 Delemont 83.1 45.1 6 9 84.84 22.2
577 Franches-Mnt 92.5 39.7 5 5 93.40 20.2
578 Moutier 85.8 36.5 12 7 33.77 20.3
579 Neuveville 76.9 43.5 17 15 5.16 20.6
580 Porrentruy 76.1 35.3 9 7 90.57 26.6
581 Broye 83.8 70.2 16 7 92.85 23.6
582 Glane 92.4 67.8 14 8 97.16 24.9
583 Gruyere 82.4 53.3 12 7 97.67 21.0
584 Sarine 82.9 45.2 16 13 91.38 24.4
585 Veveyse 87.1 64.5 14 6 98.61 24.5
586 Aigle 64.1 62.0 21 12 8.52 16.5
587 Aubonne 66.9 67.5 14 7 2.27 19.1
588 Avenches 68.9 60.7 19 12 4.43 22.7
589 Cossonay 61.7 69.3 22 5 2.82 18.7
590 Echallens 68.3 72.6 18 2 24.20 21.2
591 Grandson 71.7 34.0 17 8 3.30 20.0
592 Lausanne 55.7 19.4 26 28 12.11 20.2
593 La Vallee 54.3 15.2 31 20 2.15 10.8
594 Lavaux 65.1 73.0 19 9 2.84 20.0
595 Morges 65.5 59.8 22 10 5.23 18.0
596 Moudon 65.0 55.1 14 3 4.52 22.4
597 Nyone 56.6 50.9 22 12 15.14 16.7
598 Orbe 57.4 54.1 20 6 4.20 15.3
599 Oron 72.5 71.2 12 1 2.40 21.0
600 Payerne 74.2 58.1 14 8 5.23 23.8
601 Paysd'enhaut 72.0 63.5 6 3 2.56 18.0
602 Rolle 60.5 60.8 16 10 7.72 16.3
603 Vevey 58.3 26.8 25 19 18.46 20.9
604 Yverdon 65.4 49.5 15 8 6.10 22.5
605 Conthey 75.5 85.9 3 2 99.71 15.1
606 Entremont 69.3 84.9 7 6 99.68 19.8
607 Herens 77.3 89.7 5 2 100.00 18.3
608 Martigwy 70.5 78.2 12 6 98.96 19.4
609 Monthey 79.4 64.9 7 3 98.22 20.2
610 St Maurice 65.0 75.9 9 9 99.06 17.8
611 Sierre 92.2 84.6 3 3 99.46 16.3
612 Sion 79.3 63.1 13 13 96.83 18.1
613 Boudry 70.4 38.4 26 12 5.62 20.3
614 La Chauxdfnd 65.7 7.7 29 11 13.79 20.5
615 Le Locle 72.7 16.7 22 13 11.22 18.9
616 Neuchatel 64.4 17.6 35 32 16.92 23.0
617 Val de Ruz 77.6 37.6 15 7 4.97 20.0
618 ValdeTravers 67.6 18.7 25 7 8.65 19.5
619 V. De Geneve 35.0 1.2 37 53 42.34 18.0
620 Rive Droite 44.7 46.6 16 29 50.43 18.2
621 Rive Gauche 42.8 27.7 22 29 58.33 19.3
622 >
623

624 >Exercise10

625 1. Access the data set cars from the base library of R
626 i) Construct Boxplot for the variables in it.
627 ii) Obtain the summary of the variables
628
629 data(cars);
630 > d1=cars
631 > attach(d1)
632 > dim(d1)
633 [1] 50 2
634 > names(d1)
635 [1] "speed" "dist"
636 > s=speed;
637 > boxplot(s,xlab="s

638
639
640

641
642
643 >d1[49,]
644 Speed dist
645 49 24 120

646
647
648

You might also like