Вот начальный подход к вашей проблеме интеллектуального анализа текста (изначально учитывая трудности с определением правил).
Прежде всего, некоторые данные (обратите внимание, что я добавил еще несколько строк респондентов):
x <- c("2. Energy in Northern Ireland",
"Q1. What lessons can we learn from elsewhere in addressing energy within an",
"overarching climate action framework?",
"Q2. What are the key considerations for decarbonising Northern Ireland’s energy",
"sector given existing linkages to other jurisdictions?",
"Q3. To what extent should Northern Ireland implement the key energy-related",
"recommendations from the CCC ‘Reducing Emissions in Northern Ireland’",
"report?",
"Q4. Do you agree with the 30-year timeframe? If not, please state your preferred",
"approach and reasons.",
"Respondent response text xxxxxxxx blahblahvlahblah",
"blahblablah and so on",
"3. The Energy Transition in Northern Ireland",
"Q5. What are the unique characteristics of Northern Ireland that need to be",
"considered in a net zero carbon energy transition?",
"Q6. Is your organisation undertaking or planning to undertake projects to support",
"the energy transition? If so, please provide further details.",
"Respondent response text xxxxxxxx blahblahvlahblah",
"blah blah blah and so on",
"some more blah blah")
Решение теперь сначала вставляет строки вместе с paste
, а затем, используя gsub
, удаляет те части, которые встречаются между числами (заголовок) и ?
, а также предложения, начинающиеся с If
:
trimws(gsub("\\d.*\\?|If.*\\.", "", paste(x, collapse = " ")))
Результат:
[1] "Respondent response text xxxxxxxx blahblahvlahblah blah blah blah and so on some more blah blah"
Вам это поможет?