Consider the following data:
Names <- c("name1", "name2", "name3", "name4", "name1")
Methods <- c("method1","method2", "method2", "method1", "method2")
Amount <- c(5, 10, 15, 20, 25)
df <- data.frame(Names, Methods, Amount)
I want to create a new variable for the dataframe based on a condition within a condition of the df as a new column. I tried it based on 1 conditions and that worked:
df <- mutate(df, new_column = if_else(Methods=="method2", 0.05 + Amount * 1.5, NULL))
However how can I get a condition within this condition, to get for example:
name1 with method 2 and then give the new_column a value of 0.25 + amount * 0.5 ?
I tried the following code:
df <- mutate(df, new_column = if_else(Names=="name1",
if_else(Methods=="method2", 0.25 + Amount * 0.5, NULL)))
Can anybody help me please?