I am new in R . I have a data frame containing 3 columns. first one shows ID , for each household we have a uniqe ID. the other columns shows relationship(1 for father , 2 for mother and 3 for children . third columns shows their age. now i want to know how many twins are there in each family. ( twins are childs that have same age in each family) my data frame:
Id     relationship       age
1001       1              60 
1001       2              50
1001       3              20
1002       1              70
1002       2              68
1002       3              23
1002       3              27
1002       3              27
1002       3              23
1003       1              60
1003       2              40
1003       3              20
1003       3              20
result:
id                   twins
1001                    0
1002                    2
1003                    1
 
     
     
     
    