I would like to apply the ifelse condition to the following data frame according to the schema. I can do it repeatedly, but I have a lot of data.
My code:
d <- data.frame(x_1 = sample(1:100,10),x_2 = sample(1:100,10), y_1 =sample(1:100,10), y_2 =sample(1:100,10),
y_3 =sample(1:100,10), y_4 =sample(1:100,10))
ifelse(d$x_1>d$y_1, 0, d$x_1-d$y_1)
ifelse(d$x_2>d$y_2, 0, d$x_2-d$y_2)
ifelse(d$x_1>d$y_3, 0, d$x_1-d$y_3)
ifelse(d$x_2>d$y_4, 0, d$x_2-d$y_4) # x_1>y_5..., x_2>y_6,...
Edit:
My x_.* are days of the week so I have x_1...x_7. But my y_.* are many. Code should work as follows:
x_1-y_1
x_2-y_2
x_3-y_3
x_4-y_4
x_5-y_5
x_6-y_6
x_7-y_7
x_1-y_8
x_2-y_9
.
.
.