Thursday, 21 May 2015

How to divide data in different class interval to get frequency, cumulative frequency of a particular class interval:


> age=scan()
1: 20
2: 24
3: 19
4: 24
5: 18
6: 19
7: 24
8: 22
9: 23
10: 19
11: 19
12: 24
13: 2
14: 21
15: 22
16: 23
17: 24
18: 21
19: 25
20: 23
21:
Read 20 items
> range(age)
[1]  2 25
> interval=seq(1,27,2)          [taking less values for start and greater value for end to the given range]
> class=cut(age1,interval,right=F)    [to get class interval]
> freq=table(class)                             [to get frequency of individual class interval]
> freq
class
  [1,3)   [3,5)   [5,7)   [7,9)  [9,11) [11,13) [13,15) [15,17) [17,19) [19,21)
      1       0       0       0       0       0       0       0       1       5
[21,23) [23,25) [25,27)
      4       8       1


> cumfreq=cumsum(freq)
> cumfreq
  [1,3)   [3,5)   [5,7)   [7,9)  [9,11) [11,13) [13,15) [15,17) [17,19) [19,21)
      1       1       1       1       1       1       1       1       2       7
[21,23) [23,25) [25,27)
     11      19      20


No comments:

Post a Comment