Скажем, у меня есть вектор, содержащий некоторые символы, которые я хочу разбить на основе регулярного выражения.R: Регулярное выражение в strsplit (поиск "," затем заглавная буква)
Чтобы быть более точным, я хочу разбить строки на запятую, а затем пробел, а затем заглавную букву (по моему мнению, команда regex
выглядит так: /(, [A-Z])/g
(которая отлично работает, когда я попробуйте here)).
Когда я пытаюсь добиться этого в r
, то regex
, кажется, не работает, например:
x <- c("Non MMF investment funds, Insurance corporations, Assets (Net Acquisition of), Loans, Long-term original maturity (over 1 year or no stated maturity)",
"Non financial corporations, Financial corporations other than MFIs, insurance corporations, pension funds and non-MMF investment funds, Assets (Net Acquisition of), Loans, Short-term original maturity (up to 1 year)")
strsplit(x, "/(, [A-Z])/g")
[[1]]
[1] "Non MMF investment funds, Insurance corporations, Assets (Net Acquisition of), Loans, Long-term original maturity (over 1 year or no stated maturity)"
[[2]]
[1] "Non financial corporations, Financial corporations other than MFIs, insurance corporations, pension funds and non-MMF investment funds, Assets (Net Acquisition of), Loans, Short-term original maturity (up to 1 year)"
Он не находит раскола. Что я здесь делаю неправильно?
Любая помощь очень ценится!
Вы не должны использовать '/.../ g'. Это не JS. И я думаю, вы не хотите опускать письмо, не так ли? Попробуйте [this] (http://ideone.com/YfnJWL). –
Разделители не используются в R, а функция 'strsplit' потребляет символы. – hwnd