Rolf Turner wrote:
>
> The issue worrying Wacek was presumably the fact that
> the original poster was treating the ``B'' variable as
> being character, rather than numeric.
>
> So (presumably) what he *really* wanted to say was
> (something like)
>
> ifelse(B%in%as.character(0:9),"A","B")
yepp.
David Winsemius wrote:
>
> On Nov 19, 2008, at 8:38 PM, Wacek Kusnierczyk wrote:
>
>> Jorge Ivan Velez wrote:
>>>
B=0:12
B
>>> [1] 0 1 2 3 4 5 6 7 8 9 10 11 12
>>>
ifelse(B%in%c(0:9),'A','B')
>>> [1] "A" "A" "A" "A" "A" "A" "A" "A" "A" "A" "B" "B" "B"
>>>
>>>
>>
>
The previous solutions assume you are only interested in one small interval,
but if your original example is just a simplified version, and the real
problem is multiple, possibly large, intervals, you might want to try
something like this:
c(NA,"A","B")[1+findInterval( <>, c(0,9+1) ) ]
which
The issue worrying Wacek was presumably the fact that
the original poster was treating the ``B'' variable as
being character, rather than numeric.
So (presumably) what he *really* wanted to say was
(something like)
ifelse(B%in%as.character(0:9),"A","B")
Of course this is sheer pedantry. I'm s
On Nov 19, 2008, at 8:38 PM, Wacek Kusnierczyk wrote:
Jorge Ivan Velez wrote:
B=0:12
B
[1] 0 1 2 3 4 5 6 7 8 9 10 11 12
ifelse(B%in%c(0:9),'A','B')
[1] "A" "A" "A" "A" "A" "A" "A" "A" "A" "A" "B" "B" "B"
given the example, the solution would rather be
if (B %in% as.chara
Jorge Ivan Velez wrote:
>
>> B=0:12
>> B
>>
> [1] 0 1 2 3 4 5 6 7 8 9 10 11 12
>
>> ifelse(B%in%c(0:9),'A','B')
>>
> [1] "A" "A" "A" "A" "A" "A" "A" "A" "A" "A" "B" "B" "B"
>
>
given the example, the solution would rather be
if (B %in% as.character(0:9)) "A" else "B"
in addition to %in% and depending on what the general principle behind the
setup is:
you may want to have a look into switch (e.g. if there happen to be "C"s
and "D"s...).
or, of course you can check for B being between 0 and 9 rather than being the
respective integers:
ifelse ((B > 0) && (B
I'm sorry, a typo:
> B=0:12
> B
[1] 0 1 2 3 4 5 6 7 8 9 10 11 12
> ifelse(B%in%c(0:9),'A','B')
[1] "A" "A" "A" "A" "A" "A" "A" "A" "A" "A" "B" "B" "B"
HTH,
Jorge
On Wed, Nov 19, 2008 at 5:16 PM, Jorge Ivan Velez
<[EMAIL PROTECTED]>wrote:
>
> Dear CE.KA,
>
> Try this:
>
> B=0:12
>
Dear CE.KA,
Try this:
B=0:12
> B
[1] 0 1 2 3 4 5 6 7 8 9 10 11 12
> ifelse(B%in%c(0,9),'A','B')
[1] "A" "B" "B" "B" "B" "B" "B" "B" "B" "A" "B" "B" "B"
HTH,
Jorge
On Wed, Nov 19, 2008 at 4:42 PM, CE.KA <[EMAIL PROTECTED]> wrote:
>
> Hi R users,
>
> Is there a way to simplify thi
Hi R users,
Is there a way to simplify this instruction:
ifelse(B=="0","A",
ifelse(B=="1","A",
ifelse(B=="2","A",
ifelse(B=="3","A",
ifelse(B=="4","A",
ifelse(B=="5","A",
ifelse(B=="6","A",
ifelse(B=="7","A",
ifelse(B=="8","A",
ifelse(B=="9","A","B"))
i am looking for something like this
10 matches
Mail list logo