Hi i would like to add a column (agecat) based on the first column (age) of this data:
age sex cp trestbps chol fbs restecg thalach exang oldpeak slope ca thal num
1   63   1  1      145  233   1       2     150     0     2.3     3  0    6   0
2   67   1  4      160  286   0       2     108     1     1.5     2  3    3   2
3   67   1  4      120  229   0       2     129     1     2.6     2  2    7   1
4   37   1  3      130  250   0       0     187     0     3.5     3  0    3   0
5   41   0  2      130  204   0       2     172     0     1.4     1  0    3   0
6   56   1  2      120  236   0       0     178     0     0.8     1  0    3   0
7   62   0  4      140  268   0       2     160     0     3.6     3  2    3   3
8   57   0  4      120  354   0       0     163     1     0.6     1  0    3   0
9   63   1  4      130  254   0       2     147     0     1.4     2  1    7   2
10  53   1  4      140  203   1       2     155     1     3.1     3  0    7   1
11  57   1  4      140  192   0       0     148     0     0.4     2  0    6   0
12  56   0  2      140  294   0       2     153     0     1.3     2  0    3   0
13  56   1  3      130  256   1       2     142     1     0.6     2  1    6   2
14  44   1  2      120  263   0       0     173     0     0.0     1  0    7   0
15  52   1  3      172  199   1       0     162     0     0.5     1  0    7   0
16  57   1  3      150  168   0       0     174     0     1.6     1  0    3   0
17  48   1  2      110  229   0       0     168     0     1.0     3  0    7   1
18  54   1  4      140  239   0       0     160     0     1.2     1  0    3   0
19  48   0  3      130  275   0       0     139     0     0.2     1  0    3   0
20  49   1  2      130  266   0       0     171     0     0.6     1  0    3   0
21  64   1  1      110  211   0       2     144     1     1.8     2  0    3   0
22  58   0  1      150  283   1       2     162     0     1.0     1  0    3   0
23  58   1  2      120  284   0       2     160     0     1.8     2  0    3   1
24  58   1  3      132  224   0       2     173     0     3.2     1  2    7   3
25  60   1  4      130  206   0       2     132     1     2.4     2  2    7   4
Here is my code so long :
a$agecat <- if(a$age>=25&a$age<40) {
- print("[25:40)years")
 - } else if(a$age>=40&a$age<65) {
 - print("[40:65)years")
 - } else if(a$age>=65&a$age<80) {
 - print("[65:80)years")
 - } else {
 - print(NULL)
 - }
 
It gives me the same answer by each number "[40:65)years". How can I change the error? I need to create a column 'agent' that categorise the age by [25:40) & [40:65) & [65:80). Please help!