[R] finding birth position
jim holtman
jholtman at gmail.com
Fri Oct 26 03:45:02 CEST 2007
You might want to consider another representation, but it would depend
on how you want to use it. Here is a 'list' that records for each row
the position of the boys; does this start to give you the type of data
that you want? These are the numeric values of where the boys occur.
> x.m
b1 b2 b3 b4 b5 b6
[1,] 1 2 1 2 NA NA
[2,] 2 2 NA NA NA NA
[3,] 1 2 1 1 1 NA
[4,] 2 1 NA NA NA NA
[5,] 1 NA NA NA NA NA
[6,] 2 1 2 1 NA NA
> apply(x.m, 1, function(a)which(a == 1))
[[1]]
b1 b3
1 3
[[2]]
named integer(0)
[[3]]
b1 b3 b4 b5
1 3 4 5
[[4]]
b2
2
[[5]]
b1
1
[[6]]
b2 b4
2 4
>
On 10/25/07, Deepankar Basu <basu.15 at osu.edu> wrote:
> Hi All,
>
> I have data on the sequence of births for families with completed
> fertility cycle (in a data frame); the relevant variables are called b1,
> b2, b3, b4, b5, b6 and record the birth of the first, second, ..., sixth
> child. So,
> b1=1 if the first birth is male,
> b1=2 if the first birth is female,
> and b1=NA if the family did not record any first birth.
>
> Similarly for b2, b3, b4, b5 and b6.
>
> I want to record the positions of the male children within their
> family's birth history. So, I was thinking of creating six variables
> boy_1, boy_2, ..., boy_6. boy_1 would record the position of the first
> boy, boy_2 would record the position of the second boy and so on till
> boy_6. I want to assign a value of zero to boy_i if the family in
> question did not have the i_th boy.
>
> I am not sure how best to do this (i.e., whether to create variables as
> I have suggested or do something else) and would appreciate any
> suggestions. Later, I want to use the information on the position of the
> male births to compute a likelihood function and do an MLE.
>
> Here is how my data frame would look:
>
> b1 b2 b3 b4 b5 b6
> 1 2 1 2 NA NA
> 2 2 NA NA NA NA
> 1 2 1 1 1 NA
> 2 1 NA NA NA NA
> 1 NA NA NA NA NA
> 2 1 2 1 NA NA
>
> Thanks in advance.
>
> Deepankar
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list