I have a big dataset with 8013 participants assessed at 3 time points. My outcome variables are binary (presence/absence of intimate partner violence during the pandemic 0/1, presence/absence of intimate partner violence before the pandemic 0/1, presence/absence of domestic violence before the pandemic 0/1,presence/absence of domestic violence during the pandemic 0/1). I want to create an ordinal variable (no violence at all 0/violence starting during the pandemic 1/violence starting during the pandemic 2). I suppose I have to create a function with if statements, and I did, but all I get is an item with length 1 (!!!) and value 0. There are still quite some missing data in the dataset, and I still haven't decided how to handle them. Here is an example of the last code I made, after trying several others. I have to admit that in general I am not so experienced in coding, I started 3 months ago, and I do make syntax mistakes quite often, butone of those codes worked, just the result wasn't what I expected.
onset_viol<-function(0,1,2){if(COMET$viol_bef(1)|COMET$chil_bef(1)){return(1)}else{return(ifelse(COMET$viol_dur(1)|COMET$chil_dur(1)),2,0))}0} COMET$onset_viol=ifelse((COMET$viol_bef)&&(COMET$viol_dur)&&(COMET$chil_bef)&&(COMET$chil_dur)==0,0,(if((COMET$viol_bef)|(COMET$chil_bef)==1)print(1)else(if((COMET$viol_dur)|(COMET$chil_dur)==1)print(2)))) COMET$onset_viol
Aucun commentaire:
Enregistrer un commentaire