我有一個看起來像這樣的字符數據:的R - 組特定列表項
x= c("Clause 1 - AGREEMENT. Buyer agrees to buy, and Seller agrees to sell, the Property described below on the terms and conditions set forth in this contract.",
"Clause 2 - Buyer. Buyer, will take title to the Property described below:",
"Item 2.1 - Seller. Seller, is the current owner of the Property described below assignable by Buyer without Seller’s prior written consent.",
"Clause 3 - Inclusions. The Purchase Price includes the following items: ",
"Item 3.1 - Fixtures. If attached to the Property on the date of this Contract, the following items are included unless")
我tryng將所有項目到列表中的條款。基本上,我希望它這樣做
x[grep("Clause . - ", x)]= c(x[1], paste(x[2], x[3]), paste(x[4], x[5]))
這
x= x[grep("Clause . - ", x)]
但動態。我怎樣才能做到這一點,而不需要指定我想要組合的列表項呢?謝謝你們。
不錯!謝謝!這解決了我70%的問題。但爲了解決其他問題,是否可以使用'grep(「Clause。 - 」,x)''的索引來生成您稱爲nums的變量,而不是'gsub'?直到它找到一個非缺失的號碼爲止的代表號碼 – victor
你可以發佈一個示例,這是不工作?我發佈的模式至少在可能的數字後面至少匹配一個句點和零個或多個其他數字 – Zelazny7