I have a dataframe containing strings with various formats (words, cases, special characters, spaces, hyphen, overlapping words). These were selected by surveyors from a pre-defined list. But the surveyor could select multiple terms for each row. What I would like to do is recognise where these pre-defined terms occur and place them on a new row and duplicate all other columns. Some example data where the pre-defined terms are different pressures:
Pre_defined_pressures <- c("Urbanisation", "Land cover (general)", "Agriculture / Horticulture", "Water Quality", "General-effects")
Surveyor_df <- as.data.frame(c("A","B","C","D"))
colnames(Surveyor_df ) <- "ID"
Surveyor_df$Year <- c(1999,1999,2000,2000)
Surveyor_df$Pressure <- c("Urbanisation Land cover (general)",
"Urbanisation Land cover (general) Agriculture / Horticulture General-effects",
"Urbanisation Land cover (general) Water Quality General-effects",
"Urbanisation Land cover (general) Agriculture / Horticulture Water Quality General-effects")
How the correct data frame should look.
Correct_df <- as.data.frame(c("A","A","B","B","B","B","C","C","C","C","D","D","D","D","D"))
colnames(Correct_df ) <- "ID"
Correct_df$Year <- c(1999,1999,1999,1999,1999,1999,2000,2000,2000,2000,2000,2000,2000,2000,2000)
Correct_df$Pressure <- c("Urbanisation","Land cover (general)",
"Urbanisation","Land cover (general)","Agriculture / Horticulture","General-effects",
"Urbanisation", "Land cover (general)", "Water Quality", "General-effects",
"Urbanisation", "Land cover (general)", "Agriculture / Horticulture", "Water Quality","General-effects")