Skip to content
Back to formatted view

Raw Message

Message-ID: <BANLkTin4Y1i8qSJNMnTvLUG_qCDxMe+0_w@mail.gmail.com>
Date: 2011-04-26T18:34:10Z
From: Sarah Goslee
Subject: Tell the difference between characters
In-Reply-To: <1303841373053-3476130.post@n4.nabble.com>

Hi Lisa,

On Tue, Apr 26, 2011 at 2:09 PM, Lisa <lisajca at gmail.com> wrote:
> Dear all,
>
> I just want to determine if the characters in a character string are the
> same or not. For example,
>
> temp <- c("aa", "aA", "ab")
>
> How do I determine the first one have the two same ?a?, and the second and
> third have the different characters? Thanks in advance.

Is this what you're looking for?

testchar <- function(x)
{
substring(x, 1, 1) == substring(x, 2, 2)
}


> testchar("aa")
[1] TRUE
> testchar("aB")
[1] FALSE
>
>
> temp <- c("aa", "aA", "ab")
>
> sapply(temp, testchar)
   aa    aA    ab
 TRUE FALSE FALSE


-- 
Sarah Goslee
http://www.functionaldiversity.org