mardi 27 juin 2017

ifelse r - x and y lengths differ

I'm trying to use an ifelse on an array called "OutComes" but it's giving me some trouble.

>  PersonNumber Risk_Factor OC_Death OnsetAge Clinical CS_Death Cure AC_Death
>[1,]            1           1 99.69098       NA       NA       NA   NA       NA
>[2,]            2           1 60.68009       NA       NA       NA   NA       NA
>[3,]            3           0 88.67483       NA       NA       NA   NA       NA
>[4,]            4           0 87.60846       NA       NA       NA   NA       NA
>[5,]            5           0 78.23118       NA       NA       NA   NA       NA

Now I will try to use an apply to analyse this table's Risk_Factor Column and apply one of two functions to replace the OnsetAge column's NA's.

I've been using an apply function -

apply(OutComes, 1, function(x)ifelse(OutComes[,"Risk_Factor"] == 1, 
                                      HighOnsetFunction(x), OnsetFunction(x))

However this obviously won't work as the ifelse itself won't work. the error being -

Error in xy.coords(x, y) : 'x' and 'y' lengths differ

I'm not sure what's going on in this ifelse or what the x and y lengths are.

Aucun commentaire:

Enregistrer un commentaire