mardi 26 novembre 2019

How to replace values in the columns of a dataframe based on the values in the other column in R?

I have a dataframe containing the safety data for 100 patients. There are different safety factors for each patient with the size of that specific factor.

   redness_d0 size_of_redness_d0 hardness_d0 size_of_hardness_d0 redness_d1 size_of_redness_d1 ...
P1  1              20             
P2  1              NA
P3  0              NA
.
.
.

Here redness=1 means there was redness and redness=0 means there was no redness, and therefore the redness_size was not reported.
In order to find what proportion of the data is missing I need to code the data as follows: if (the column containing redness=1 & the column containing redness_size=NA) then (the column containing redness_size<-NA) else if (the column containing redness=0 then the column containing redness_size<-0) to have this coded for d0,d1,.. and to repeat this process for the other variables like hardness, swelling and etc. Any ideas how one could implement this in R?

Aucun commentaire:

Enregistrer un commentaire