-1

enter image description here

I have a column like this but I need to separate the weight digits from the chips name. Using grepl() function.

productWords[grepl(pattern = "![:digit:]", x= productWords)]

it's not working :/

  • Hi, Welcome to Stack Overflow. Your code is pasted as a picture, making it difficult fro people to help you. Also the error message would be helpful to know. Please consider looking at how to make a reproducible example here https://stackoverflow.com/help/minimal-reproducible-example with additional tips [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Mark Neal Jul 17 '20 at 04:44

1 Answers1

0

Try this with stringr package

x <- "Natural Chip 175g"
stringr::str_extract(x, '[0-9]{3}g')

If weights can have more than 3 digits, try this -

stringr::str_extract(x, '[0-9]+g')
john
  • 1,026
  • 8
  • 19