pdlyr mutate string extract
library(dplyr)
# Assuming you have a data frame named 'df' with a column named 'text'
df <- df %>%
mutate(new_column = str_extract(text, pattern))
- Load the
dplyr
library:R library(dplyr)
- Assuming you have a data frame named 'df' with a column named 'text':
R df <- df %>%
- Use the
mutate
function to create a new column named 'new_column':R mutate(new_column = str_extract(text, pattern))
mutate
: Function fromdplyr
to add new variables to the data frame.new_column
: The name of the new column to be created.str_extract
: Function fromstringr
library to extract the first occurrence of a pattern in a string.text
: The column from which to extract the pattern.pattern
: The pattern to be extracted from the 'text' column.
Replace 'df' with the actual name of your data frame and adjust 'text' and 'pattern' accordingly.