[R] Find index of a string inside a string?

2010-10-25 Thread yoav baranan
Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I

Re: [R] Find index of a string inside a string?

2010-10-25 Thread Nick Sabbe
-boun...@r-project.org] On Behalf Of yoav baranan Sent: maandag 25 oktober 2010 13:27 To: r-help@r-project.org Subject: [R] Find index of a string inside a string? Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located

Re: [R] Find index of a string inside a string?

2010-10-25 Thread yoav baranan
...@ugent.be To: ybara...@hotmail.com; r-help@r-project.org Subject: RE: [R] Find index of a string inside a string? Date: Mon, 25 Oct 2010 13:42:23 +0200 For simple searches, use grep with fixed=TRUE. Check ?grep. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be

Re: [R] Find index of a string inside a string?

2010-10-25 Thread jim holtman
I think what you want is 'regexpr': regexpr(bcd, aabcd) [1] 3 attr(,match.length) [1] 3 On Mon, Oct 25, 2010 at 7:27 AM, yoav baranan ybara...@hotmail.com wrote: Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is

Re: [R] Find index of a string inside a string?

2010-10-25 Thread Hadley Wickham
Or str_locate: library(stringr) str_locate(aabcd, bcd) Hadley On Mon, Oct 25, 2010 at 5:53 AM, jim holtman jholt...@gmail.com wrote: I think what you want is 'regexpr': regexpr(bcd, aabcd) [1] 3 attr(,match.length) [1] 3 On Mon, Oct 25, 2010 at 7:27 AM, yoav baranan

Re: [R] Find index of a string inside a string?

2010-10-25 Thread yoav baranan
Indeed, thank you. The exact equivalent of index in SAS seems to me: regexpr(bcd, aabcd, fixed=T)[1] [1] 3 Date: Mon, 25 Oct 2010 07:53:22 -0400 Subject: Re: [R] Find index of a string inside a string? From: jholt...@gmail.com To: ybara...@hotmail.com CC: r-help@r-project.org I think