I have multiple strings (so-called DOIs) like this:
doi1 <- "10.1057/bp.2009.9"
doi2 <- "10.1057/bp.2015.4"
doi3 <- "10.1057/bp.2008.12"
How do I best extract the common beginnings of the strings?
The correct output should be 10.1057/bp.20.
(My first guess was to use identical(), but that function can only compare two whole strings)
The package ‘Biobase’ has this implemented as
lcPrefix.But implementing this oneself isn’t hard; here’s another quick and dirty version (careful, this was only tested on a handful of cases):