-3

enter image description here

I have a data with millions of rows. i want to do some data manipulations in R.

The below image describes the conditions. I want final result stored in Result variable. Here NA means not applicable for this logic.

Outputdata is my final dataset. Create a new variable Result and insert values according to below conditions.

Case 1: If Lost = 1 and PPP >= 0.8 then Result = PPP Case 2: If Lost = 1 and PPP < 0.8 then Result = 0.935294

Also, if Result is non blank then apply Case 2 for those rows. If Result has a value due to previous cases don't over write the value.

Please help me. R is very new for me.

  • Please read about how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Dec 29 '17 at 15:50

1 Answers1

1

If df stores your data frame just do (with dplyr package):

df %>% mutate(Result=ifelse( Lost==1 & PPP >=0.8, as.character(PPP), ifelse(Lost==1 & PPP<0.8,0.935294,NA ))
Hugo Silva
  • 199
  • 9