Hi I am trying to understand the following variable assignment in C, and try re-write it in R. I use R often but have only really glanced at C.
int age,int b_AF,int b_ra,int b_renal,int b_treatedhyp,int b_type2,double bmi,int ethrisk,int fh_cvd,double rati,double sbp,int smoke_cat,int surv,double town
)
{
double survivor[3] = {
0,
0.996994316577911,
0.993941843509674
};
a = /*pre assigned*/
double score = 100.0 * (1 - pow(survivor[surv], exp(a)) );
return(score);
}
how does survivor[surv] work in this context? An explanation would be helpful, and any input on how to do the assignment in R would be a bonus.
Thanks very much!
This is an aggregate initializer:
and is equivalent to:
and
survivor[surv]is the value stored at index of thesurvivorarray. Array indexes run from0toN - 1so ifsurvwas1thensurvivor[surv]has value of0.996994316577911.Note, the function as currently written does not check that
survis a valid index for the arraysurvivor(i.e.surv > -1andsurv < 3) and runs the risk of undefined behaviour.