Yalnızca R'de "-" ile birleştirilen sözcükler nasıl belirlenir? [çiftleme]

Dec 13 2020

Diyelim ki, R'de aşağıdaki metin var:

x = "The effects in the medium-term of an appreciation of the exchange rate are still to be carefully assessed in our projections. However, we can observe in the short-term that the our pogramme of purchasing asset-backed securities had a positive impact on overall economic activity"

Yalnızca aşağıdakileri nasıl edinebilirim:

# medium-term
# short-term
# asset-backed 

Temel olarak, yalnızca "-" ile bağlantılı kelimeleri çıkarmam gerekir.

Biri bana yardım edebilir mi?

Teşekkürler!

Yanıtlar

1 KarthikS Dec 13 2020 at 17:45

Bu çalışıyor mu:

library(stringr)
str_extract_all(x, '\\b[a-z]+-[a-z]+\\b')[[1]]
[1] "medium-term"  "short-term"   "asset-backed"
1 RonakShah Dec 13 2020 at 17:47

R tabanında şunları kullanabilirsiniz:

regmatches(x, gregexpr('\\w+-\\w+', x))[[1]]
#[1] "medium-term"  "short-term"   "asset-backed"