0

I have an R data frame named "t" that looks like this:

         counts Freq
1        0  316
2        1  194
3        2  168
4        3  177
5        4  152
6        5  154
7        6  125
8        7  115
9        8  112
10       9  122
11      10   91
12      11   96
13      12   71
14      13   70
15      14   57
16      15   56
17      16   64
18      17   46
19      18   55
20      19   36
21      20   38
22      21   47
23      22   39
24      23   30
25      24   34
26      25   34
27      26   25
28      27   19
29      28   18
30      29   22
31      30   15
32      31   14
33      32   13
34      33   16
35      34   14
36      35    9
37      36   15
38      37   10
39      38   10
40      39   13
41      40   15
42      41   11
43      42   10
44      43   13
45      44    5
46      45   14
47      46    8
48      47    9
49      48    6
50      49    9
51      50    3
52      51    6
53      52   10
54      53    3
55      54    3
56      55    4
57      56    6
58      57    5
59      58    5
60      59    1
61      60    4
62      61   10
63      62    4
64      63    5
65      64    7
66      65    5
67      66    4
68      67    8
69      68    2
70      69    1
71      70    1
72      71    3
73      72    5
74      73    1
75      74    2
76      75    1
77      76    3
78      77    2
79      78    2
80      79    1
81      80    3
82      81    2
83      82    1
84      84    3
85      85    3
86      86    3
87      87    2
88      89    2
89      90    2
90      93    1
91      94    1
92      95    3
93      96    2
94      97    1
95      98    3
96      99    3
97     100    2
98     102    1
99     103    3
100    106    2
101    109    1
102    111    1
103    112    2
104    113    2
105    114    3
106    118    1
107    119    1
108    120    1
109    122    1
110    128    1
111    132    1
112    138    1
113    139    1
114    141    1
115    143    1
116    144    2
117    146    1
118    150    1
119    157    1
120    160    1
121    161    1
122    167    1
123    171    1
124    176    1
125    177    1
126    179    1
127    195    1
128    205    1
129    237    1
130    241    1
131    253    1
132    256    1
133    260    1
134    275    1
135    362    1
136    422    1
137    436    1
138    463    1
139   1819    1

I am trying to generate a frequency distribution of the variable count. However, when i type this commands in the R command prompt:

> duration = t$counts
> range(duration)

i get this error:

Error in Summary.factor(1:139, na.rm = FALSE) : 
  ‘range’ not meaningful for factors

I am a newbie in R. What i can i be possibly be doing wrong?

tom sawyer
  • 47
  • 1
  • 2
  • 9
  • it means `counts` (and so `duration`) is of class `factor`. Check with `class(counts)`. Cast it as int with `as.integer(counts)` – GGamba Feb 17 '17 at 19:50
  • BTW, `t` is a bad name for a variable. There is a function called `t` (transpose) and it could be confused with `T` which means `TRUE`. – G5W Feb 17 '17 at 19:51
  • How do i mark this question as answered? – tom sawyer Feb 17 '17 at 21:00
  • You can't. None has provided an answer, these are only comments and only answers can be accepted. Anyway this is a common problem (factor handling in R), so I propose this as a duplicate – digEmAll Feb 17 '17 at 21:49
  • As you can see in the accepted answer of the duplicate, you can convert your column using `duration <- as.numeric(levels(f))[f]` – digEmAll Feb 17 '17 at 21:51
  • `as.integer(counts)` is wrong because you need to convert the factor labels to a number, not the underlying factor indexes. – digEmAll Feb 17 '17 at 21:53
  • @digEmAll...does this explain why i am not able to produce a frequency table after following the instructions on this [page](http://www.r-tutor.com/elementary-statistics/quantitative-data/relative-frequency-distribution-quantitative-data) ? – tom sawyer Feb 18 '17 at 09:08

0 Answers0