mercredi 3 février 2021

LOOP OR FUNCTION IN R TO CREATE A NEW DATAFRAME'S COLUMN

I have a dataframe with column A and B containing numeric values from 1 to 10.

    A B
1   5 9
2   7 2
3   2 1
4   1 9

I have add to the dataframe a new column OCCU with in each row the value HOPD if one of the following two conditions hold : 3<A<9 or 3<B<9. otherwise the value to assign is LOPD. For example in the above case, individual 1 and 2 have OCCU = HOPD, while 3 and 4 have OCCU = LOPD

THANKS IN ADVANCE

Aucun commentaire:

Enregistrer un commentaire