I have problems solving this issue. Let's assume a dataframe like this:
COL_1 COL_2 COL_3 COL_4
1 UP_RED_LIGHT 23.43 UP_R
2 UP_YELLOW_LIGHT 23.33 UP_Y
3 DP_GREEN_DARK 43.76 DP_G
4 DP_BROWN_LIGHT 45.65 DP_B
5 R_BLACK_DARK 12.32 R_B
I want to catch every string in this dataframe that starts with "DP_" and delete it from the string.
The result I want to have:
COL_1 COL_2 COL_3 COL_4
1 UP_RED_LIGHT 23.43 UP_R
2 UP_YELLOW_LIGHT 23.33 UP_Y
3 GREEN_DARK 43.76 G
4 BROWN_LIGHT 45.65 B
5 R_BLACK_DARK 12.32 R_B
So basically, I want to replace with '' whenever a string in my dataframe starts with DP_, in every column. The fact that starts is important, if it was in the middle of the string the solution should leave it. This is why solution like this:
df<- gsub('DP_', '', df)
don't work for me.
Is there a nice and clean solution to this?
Thank you in advance for the help.