Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个看起来像这样的文本:
txt <- "w.raw.median"
我想在两个句点(.)之间提取第二个单词,给出这个输出
.
> raw
但是为什么这不起作用
gsub(".*\\.", "", txt)
正确的方法是什么?
试试这个:
gsub(".*\\.(.*)\\..*", "\\1", txt) [1] "raw"
还要考虑
strsplit(txt,'.',fixed=TRUE)[[1]][2]
对于(稍微)更具可读性的版本