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.
Asked
Active
Viewed 1,750 times
3
-
1Perhaps 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 Answers
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