I have a long data frame that looks like this
df <- data.frame(col1=c(1,2,3), col2=c(3,4,5), col3=c("s1:i:2", "s1:i:3", "dv:i:2"), col4=c("dv:i:4", "dv:i:4", "NA"))
>df
col1 col2 col3 col4
1 1 3 s1:i:2 dv:i:4
2 2 4 s1:i:3 dv:i:4
3 3 5 dv:i:2 NA
I am interested in the values that start with "dv". However, in my table, those values could be on different columns according to the presence or absence of other values. In this example, because of the lack of one s1 value, the dv value is not anymore in col4 but it is on col3. Do you know how I could write all the dv values on a single column? I guess using something like grepl could help, but I am unsure how to do it.
I forgot to add that "dv" could be almost in any column, not only col3 or col4, sorry about that.