3

I need compare a vector with strings which in any case they have the same two first letters. How I do it? I know the function compare in the library compare but I don't get it to work. Thanks in advance.

pescobar
  • 177
  • 1
  • 1
  • 10
  • 1
    Perhaps you want to use `substr()`. Otherwise, pleas give an example of the data you have and the answer you want. – Jthorpe Feb 25 '15 at 17:26
  • Thank you so much. I already got do with the function `grep()` but I going to try with `substr()`. – pescobar Feb 25 '15 at 17:37

1 Answers1

2

Here is an example using strsplit. You can probably create a function using the approach.

s1 = "Cat"
s2 = "Cator"


s1.letter = strsplit(s1, split = "")[[1]]
s2.letter = strsplit(s2, split= "") [[1]]

sum(s1.letter[1:2] == s2.letter[1:2])==2

That would return True in this case

Romain
  • 839
  • 10
  • 24