I have a sample of my data as follows (real data is nearly .5 million women of childbearing age): In this dataset, I have a parity of women that consists of all children a woman has). This row continues until 30 children (ageownchild_pernum1: ageownchild_pernum30). For example, a woman has 2 children, This woman has 30 rows (filled with the age of the children) but only the first and second rows are filled with the age of the children the woman has, and other rows are filled with NA. Here I bring just two of the rows and omit others for simplicity.
library("tidyverse")
DataSet1<-
tibble(
id = c(1,2,3,4,5,6,7,8,9,10),
ageownchild_pernum1 = c(18,24,13,16,9,NA,17,13,32,7 ),
ageownchild_pernum2= c(16,NA,9 ,10,7,NA,13,11,20,5 ),
AGE= c(38,52 ,41 ,43 ,38 ,36 ,40 ,36 ,56,31),
F_curve_notch_15= c(25.14,30.28,43.33,43.33,25.14,25.14,25.14,25.14,67 ,33.77),
F_curve_notch_15.25= c(34.01,40.33,51.74,51.74,34.01,34.01,34.01,34.01,73.85,41.91),
f_curve_tilde_15= c(25.14,30.28,43.33,43.33,25.14,25.14,25.14,25.14,67 ,33.77),
f_curve_tilde_15.25= c(25.14,30.28,43.33,43.33,25.14,25.14,25.14,25.14,67 ,33.77),
)
F_curve_notch and f_curve_tilde are for ages (15 to 49,.25).
Now, I want to do this bulky procedure on my data that may reach more than a thousand lines of code.
DataSet1$low_notch <-ifelse((DataSet1$ageownchild_pernum1>=0),DataSet1$AGE -
DataSet1$ageownchild_pernum1 - 0.75,0)
DataSet1$high_notch <-ifelse((DataSet1$ageownchild_pernum1>=0),DataSet1$AGE -
DataSet1$ageownchild_pernum1 + 0.75,0)
DataSet1$low_low_notch <-ifelse((DataSet1$ageownchild_pernum1>=0),DataSet1$AGE -
DataSet1$ageownchild_pernum1 - 1.25,0)
DataSet1$high_high_notch<-ifelse((DataSet1$ageownchild_pernum1>=0),DataSet1$AGE -
DataSet1$ageownchild_pernum1 + 1.25,0)
DataSet1$low_low_notch <-ifelse ((DataSet1$low_low_notch>=20) & (DataSet1$low_low_notch<35)
,DataSet1$low_low_notch+0.25,DataSet1$low_low_notch)
DataSet1$high_high_notch<-ifelse ((DataSet1$high_high_notch>=20) &
(DataSet1$high_high_notch<35), DataSet1$high_high_notch+0.25, DataSet1$high_high_notch)
notch <- function(a, b,c,d){
ifelse((a<= 15)&(b>=15)&(c!= 0),0.01*d,c)
}
DataSet1$f_curve_notched_15<-mapply('notch',DataSet1$low_low_notch, DataSet1$high_high_notch,
DataSet1$f_curve_notched_15,DataSet1$f_curve_tilde_15, DataSet1$f_curve_notched_15)
This procedure, should continue for all ageownchild_pernum(1:30) and f_curve_notched(15 to 49, .25). I really appreciate any help you can provide.
Is it what you are expecting?
And the last columnn contains the
notch()results:APPENDED
If you need a wider data shape you can append the above listed code with:
You will get something like this: