Let's say we have:
set.seed(42)
df1 <- data.frame(v1=rnorm(10) , v2=rnorm(10), v3=rnorm(10), v4=rnorm(10))
as well as
df2 <- data.frame(v1=rnorm(10) , v2=rnorm(10), v3=rnorm(10), v4=rnorm(10))
vector <- c(17,21,33,41,50,63,72,81,91,10)
df1 and df2 have same column names and df2 is generated by processing of df1.
For each row in df2, I would like to replace a value that meets the condition < 0.5 in df1, with the corresponding value of the vector.
For example, if any of the columns of the first row in df1 has a value lower than 0.5, then the corresponding column(s) of the first row in df2 will have to be replaced with the first element of the vector, that is 17. For the second row, they will be replaced with 21 etc.
I picture some apply and a custom made function would do the trick but I am not able to figure it out. Thank you in advance for the solution.