I have multiple columns which contain strings of data.
(data$product, data$price, data$overview1, data$overview2, data$overview3, data$overview4)
I would like to create a new vector which only contains strings which begin with the string "Material:"
Setting the pattern for GREP
matpattern <- "((?<=Material: ).*|(?<=Materials: ).*)"
Get strings which have material at start
mat <- gregexpr(matpattern, data$Overview1, perl=TRUE)
Create vector to store string
data$material1 <- regmatches(data$Overview1, mat, invert = FALSE)
/repeat for overview2/
mat <- gregexpr(matpattern, data$Overview2, perl=TRUE)
data$material2 <- regmatches(data$Overview2, mat, invert = FALSE)
The statement
z <- cbind(material1, material2)
gives a matrix when I want a list
Is there a method to get lapply & gregexpr to work across multiple columns and then place the new strings in a single column?
I have looked below, with no avail, thanks for your help.
Convert R vector to string vector of 1 element