I am trying to fill a new column in a df of 700k records and it goes too slow with for loop and therefore want to use apply function. Not familiar with it and below is my attempt but this doesn't work. Please help
myfunc <- function(a,b,c,d) {if (a=="xyz" & b==11) {c=d}}
dataf[,'target'] <- apply(dataf, 1, function(dataf) myfunc(dataf[,'col1'],dataf[,'col2'],dataf[,'target'],dataf[,'col3']))
Adding more description -
What I have:
a b c d
x 2 p
x 2 p
x 2 p
xyz 11 p
xyz 11 p
xyz 2 p
y 2 p
y 2 p
y 2 p
What I want to achieve:
a b c d
x 2 p
x 2 p
x 2 p
xyz 11 p p
xyz 11 p p
xyz 2 p
y 2 p
y 2 p
y 2 p