Remove everything after a string in a data frame column with missing values
问题 I have a data frame resembling the extract below: Observation Identifier Value Obs001 ABC_2001 54 Obs002 ABC_2002 -2 Obs003 1 Obs004 1 Obs005 Def_2001/05 I would like to transform this data frame into a data frame where portions of the string after the "_" sign would be removed: as illustrated below: Observation Identifier_NoTime Value Obs001 ABC 54 Obs002 ABC -2 Obs003 1 Obs004 1 Obs005 Def I tried experimenting with strsplit , gsub and sub as discussed here but cannot force those commends