我是編程新手,從R開始,因爲我需要它在我的碩士課程中,有人可以幫助我逐步瞭解解決方案。有人能解釋一下函數「sub」對上面的字符向量做什麼嗎?
awards <- c("Won 1 Oscar.",
"Won 1 Oscar. Another 9 wins & 24 nominations.",
"1 win and 2 nominations.",
"2 wins & 3 nominations.",
"Nominated for 2 Golden Globes. 1 more win & 2 nominations.",
"4 wins & 1 nomination.")
sub(".*\\s([0-9]+)\\snomination.*$", "\\1", awards)
解決方案: 含有字符串的矢量:
Won 1 Oscar., 24, 2, 3, 2, 1
請刪除C++標記。 – YSC
相關文檔:https://stat.ethz.ch/R-manual/R-devel/library/base/html/grep.html和https://stat.ethz.ch/R-manual/R-devel/ library/base/html/regex.html –