Relative Content

Tag Archive for rparsingconditional-statementslapply

Conditionally parse number from text string in and assign to new column

I am attempting to conditionally parse numbers from text strings within a dataframe and then assign that parsed number to the corresponding row within the last column. The condition is grepl("apple", df$col1). Not every row will meet the condition, so the corresponding cell in the last column can be NA. Perhaps easier seen than explained: