Friends This is an elementary question. Is there is a built in R function for finding a sub-string in another string? Like strstr in C. I can easily roll my own, but if there is a built in that is one less thing I can do wrong! cheers Worik [[alternative HTML version deleted]]
On May 5, 2011, at 4:55 PM, Worik R wrote:> Friends > > This is an elementary question. Is there is a built in R function for > finding a sub-string in another string? Like strstr in C. > > I can easily roll my own, but if there is a built in that is one > less thing > I can do wrong!I have no acquaintance with that function, but perhaps: ?grep regexpr : "returns an integer vector of the same length as text giving the starting position of the first match or -1 if there is none, ..." > tst <- "abcde"; regexpr("bc", tst) [1] 2 attr(,"match.length") [1] 2 -- David Winsemius, MD West Hartford, CT
On Thu, May 5, 2011 at 4:55 PM, Worik R <worikr at gmail.com> wrote:> Friends > > This is an elementary question. ?Is there is a built in R function for > finding a sub-string in another string? ?Like strstr in C. > > I can easily roll my own, but if there is a built in that is one less thing > I can do wrong! >Try ?substr and ?substring The character processing function help pages are listed here: help.search(keyword = "character", package = "base") -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com