Reputation: 151
I want to make a warning column to warn the user of database if a condition is fulfilled. I currently have data like this.
item stock_need rto doi
PRE 24DX4SX15G 200 4800 14
PLS 12RX10SX15G 240 2400 10
ADU 24PX200ML 700 4800 8
NIS 18PX40SX11G 200 3600 4
REF 500GX12D 200 2400 20
i want to make a new column to warn the database user, if the doi less than 14 days AND rto/doi<= stock_need. So the output will be looked like this.
item stock_need rto doi rto/doi warn
PRE 24DX4SX15G 200 4800 14
PLS 12RX10SX15G 240 2400 10 240 order now
ADU 24PX200ML 700 4800 8 600 order now
NIS 18PX40SX11G 200 3600 4 900
REF 500GX12D 200 2400 20
how to done this condition? Thanx so much in advance
Upvotes: 0
Views: 50
Reputation: 1253
Assuming your data is stored in a dataframe df:
warnIdx <- (df$doi < 14) & (df$rto/df$doi <= df$stock_need) # find rows fulfilling both conditions
df$warn <- NA_character_ #add a character column
df$warn[warnIdx] <- "order now" #replace tha NAs with "order now" in said rows
Upvotes: 1