用R中的单词拆分字符串

时间:2014-03-26 10:31:36

标签: regex r strsplit

我想用两个单词分割一个字符串:

s <- "PCB153 treated HepG2 cells at T18"
strsplit(s, split = <treated><at>)

我应该写什么而不是&lt;&gt;?

我会得到:

"PCB153" "HepG2 cells" "T18"

2 个答案:

答案 0 :(得分:9)

strsplit(s, split="treated|at")
#[[1]]
#[1] "PCB153 "       " HepG2 cells " " T18" 

答案 1 :(得分:1)

您必须以字符串形式输入。拆分处理:

s <- "PCB153 treated HepG2 cells at T18"
s2 <- strsplit(s,split="treated")
unlist(s2)

拆分处理和at:

unlist(strsplit(unlist(s2),split="at"))