I have the following data below. Essentially, I want to take the value in the vector and compare it against all the values to the corresponding column in terms of position. As an example, 55 would be compared against column x in B_df. All values above or larger than 55 should remain the same while all other values be changed to a 0. The same needs to happen with 44 in A_vec. The final output should be an adjusted dataframe of B_df.
I can write a nested for loop but I would want to do this with one of the apply() functions. I think mapply() would be the right function to use but not entirely sure how you'd specify it. Any help would be appreciated!
set.seed(333)
A_vec <- c(55,44,66,77)
B_df <- data.frame(x = sample(50:59, 10),
y = sample(40:49, 10),
z = sample(60:69, 10),
aa = sample(70:79, 10))
You mentioned in your question about apply family, and tagged dplyr. Andres already gave a solution using tidyverse, so I'm adding two more solutions using base R.