0

I am trying to do an if-then statement with my data based on two fields:

  1. actual sales
  2. DRV (price that I bought the device for)

I want to create a field in R called "Coverage". If the actual sales is greater than or equal the DRV field, then fill the "Coverage" field for that specific account as "Covered. If its below, then fill with it with "Not covered".

Seems like a simple update query, but I am getting new to R and trying to figure out all the schematics of using it.

user7298979
  • 499
  • 4
  • 21
  • Welcome to StackOverflow. Please take a look at these tips on how to produce a [minimum, complete, and verifiable example](http://stackoverflow.com/help/mcve), as well as this post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Perhaps the following tips on [asking a good question](http://stackoverflow.com/help/how-to-ask) may also be worth a read. – lmo Jan 19 '17 at 18:38
  • you want `ifelse()`. see the help page by runnin `?ifelse` at the console – arvi1000 Jan 19 '17 at 18:39

1 Answers1

1

You can use ifelse() for this. If df is your data.frame,

df$coverage <- ifelse(df$actual_sales >= df$DRV, "Covered", "Not covered")
BLT
  • 2,492
  • 1
  • 24
  • 33