0

I currently have a df in R with a column called FORMULAS that looks like this:

enter image description here

What I would like to do is to isolate the formula at the first equal sign:

enter image description here

This is the code I came up with so far:

df$FORMULAS <- str_extract(df$FORMULAS, "(?<=\\} =)")

where I have tried to use the lookahead procedure, but without much luck. Is this the best approach to solve the issue? Do you have any suggestions on what am doing wrong?

Thanks so much in advance!

iraciv94
  • 782
  • 2
  • 11
  • 26

1 Answers1

0

So something like

trimws(sub(".*?=", "", x))
#[1] "a+b+c"       "a*b*c"       "a/b = c"     "bc + de = 1"

? lazily matches everything until first occurrence of "=" and replaces it with empty string using sub.

where x is

x <- c("{X} = a+b+c", "{Y} = a*b*c", "{Z} = a/b = c", "a=bc + de = 1")

Added an extra input from @Wiktor's link.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213