-1

I have some rows that need to have everything after a slash removed

x1\
myco\
myco\
myco/fungicide

is there a way I can do this?

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • Use `trimws("myco/fungicide", whitespace = "/.*")#[1] "myco"` – akrun Jul 18 '22 at 19:32
  • Does this answer your question? [removing everything after first 'backslash' in a string](https://stackoverflow.com/questions/17187552/removing-everything-after-first-backslash-in-a-string) – NelsonGon Jul 18 '22 at 19:33
  • i should have been more specific, there are many different words in this column, e.g.: herbicide/fungicide, insecticide/butane etc. – Adam France Jul 18 '22 at 19:34

1 Answers1

1

We may use trimws

df1$x1 <- trimws(df1$x1, whitespace = "/.*")
akrun
  • 874,273
  • 37
  • 540
  • 662