I have a data frame. One of the columns has string values that I want to use as a condition for the name of the other columns. For example,
df <- data.frame(
cond=c("a","b"),
aVal=c(1 , 2),
bVal=c(3 , 4)
)
I want to check the name of each column in the df row by row, if the colname does not start with cond then I want to set the value of that column to 0. The expected output here will be.
# cond aVal bVal
# 1 a 1 0
# 2 b 0 4
I am not sure how to do this with R preferably with dplyr.