-2

I'm trying to extract a substring from a string for each row in a column if it matches a specific value. Subsequently I want to add the matched substring to a new column. The substring must match either 'GET', 'POST' or 'HEAD'. The strings are in the following format: 'GET /icons/circle_logo_small.gif'.

This is my current dataframe

current df

And this the expected dataframe

expected df

Heikki
  • 2,214
  • 19
  • 34
Jannus
  • 41
  • 3
  • 1
    Add data in text form, not images. Please follow here to learn more https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1 – cropgen Apr 17 '19 at 19:56
  • I don't see your code. Did you try `?substring`? – cory Apr 17 '19 at 20:34

1 Answers1

0

You need to extract all strings before space. One way:

df$Category <- gsub( " .*$", "", df$request )

Assuming df is your dataframe

Sonny
  • 3,083
  • 1
  • 11
  • 19