[R] create group variable -- family data -- for siblings

Juliet Hannah juliet.hannah at gmail.com
Sat Oct 25 17:08:36 CEST 2008


For the following data:

famdat <- read.table(textConnection("ind momid dadid
1   18    19
2   18    19
3   18    19
4   21    22
5   21    22
6   23    25
7   23    27
8   29    30
9   31    30
10  40    41
11  NA    NA
12  50    51"),header=TRUE)
closeAllConnections();

I would like to create a label (1,2,3..) for siblings. Siblings will
be defined by those who have both the same momid and dadid, but also
those who
just have the same momid or the same dadid. In addition, there will be
those without siblings and those whose parents are missing, and they
will
get unique ids. For the data above, the result would be:

   ind momid dadid sibid
1    1    18    19      1
2    2    18    19      1
3    3    18    19      1
4    4    21    22      2
5    5    21    22      2
6    6    23    25      3
7    7    23    27      3
8    8    29    30      4
9    9    31    30      4
10  10    40    41     5
11  11    NA    NA   6
12  12    50    51     7

Thanks!

Juliet



More information about the R-help mailing list