4

I would like to split a string by two words:

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

What should I write instead of <>?

I would get:

"PCB153" "HepG2 cells" "T18"
Artem Klevtsov
  • 9,193
  • 6
  • 52
  • 57
charisz
  • 302
  • 4
  • 12

2 Answers2

9
strsplit(s, split="treated|at")
#[[1]]
#[1] "PCB153 "       " HepG2 cells " " T18" 
Roland
  • 127,288
  • 10
  • 191
  • 288
1

You have to enter it as a string. To split on treated:

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

To split on treated and at:

unlist(strsplit(unlist(s2),split="at"))
Jonas Tundo
  • 6,137
  • 2
  • 35
  • 45