0

Trim all chrs to the right of a "-" in a column

https://code.sololearn.com/cAPTWR2FzOdP/?ref=app Hi all. I am looking to trim off the hyphen (-) and anything to the right of the hyphen for each value in the "sample ID" column. So for example I would want to transform "D1-2" into "D1". Any value without a hyphen I would want to leave untouched. Very simple code is included in the link above. Apologies for this potentially being a silly question. If I misused any nomenclature I do apologise, I'm very much an R novice and also haven't been involved with the sololearn community in quite a while.

30th May 2022, 12:59 PM
Anthony
Anthony - avatar
2 Answers
+ 3
I briefly commented the approach in the script: https://code.sololearn.com/ccu7mo85vMAk/?ref=app
30th May 2022, 1:09 PM
Lisa
Lisa - avatar
+ 1
This does exactly what I need. Thanks Lisa
30th May 2022, 1:41 PM
Anthony
Anthony - avatar