Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string by words in R

Tags:

regex

r

strsplit

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"
like image 337
charisz Avatar asked Dec 25 '22 11:12

charisz


1 Answers

strsplit(s, split="treated|at")
#[[1]]
#[1] "PCB153 "       " HepG2 cells " " T18" 
like image 166
Roland Avatar answered Jan 14 '23 19:01

Roland