vendredi 20 février 2015

if Col 2 is true copy the calues from Col1 into Col 3

I have a dataset which is as follows



Id Name Description Status
1 Kyla DataMining Yes
2 Kim MonteCarlo Methods No
3 Kanye Meta-Analysis May Be
4 Bruce Optimization Yes


I am trying to create a fourth column Result which will store the values from Description column if Status == Yes, if Status == No or May Be then it will just copy the values from Status which is No or May Be. The final dataset should look like this



Id Name Description Status Result
1 Kyla DataMining Yes DataMining
2 Kim MonteCarlo Methods No No
3 Kanye Meta-Analysis May Be May Be
4 Bruce Optimization Yes Optimization


So far I tired doing this using ifelse



data1$Result <- ifelse(data1$Status == "Yes", data1$Description, data1$Status)


I dont get any error but I dont get the right results either, i am seeing some completely unrelated numbers ?? Need some help.


Aucun commentaire:

Enregistrer un commentaire