r - how can I remove part of a names in one column of a data frame? -
i have data looks
v1 v2 phenzine.mo.4213121906560.c02.name 2.376140e-05 dnium.bte.mo.02400072107987.e10.name 2.423254e-05 trene.mo.024213121906564.c09.name 2.438986e-05 tilli.mo.550760072207033.f09.name 2.495574e-05 tnolone.mo..614615111406.name 2.511859e-05
i want remove part of first column looks below
v1 v2 phenzine 2.376140e-05 dnium.bte 2.423254e-05 trene 2.438986e-05 tilli 2.495574e-05 tnolone 2.511859e-05
i know must use grep or sub not
you can try below regex if 'mo' common elements
df1$v1 <- sub('\\.mo.*', '', df1$v1)
suppose, want remove strings .
followed first capital letter
sub('\\.[a-z].*', '', df1$v1) #[1] "phenzine" "dnium.bte" "trene" "tilli" "tnolone"
or if more specific
sub('\\.(mo|no|nr).*', '', df1$v1) #[1] "phenzine" "dnium.bte" "trene" "tilli" "tnolone"
Comments
Post a Comment