Skip to content
Back to formatted view

Raw Message

Message-ID: <CAM_vju=8gRGXC=USLJVVVYUzG2inDr_1_02xM615RL+p=oD0uA@mail.gmail.com>
Date: 2011-10-30T19:57:08Z
From: Sarah Goslee
Subject: why the a[-indx] does not work?
In-Reply-To: <1320004207.63930.YahooMailNeo@web120110.mail.ne1.yahoo.com>

ifelse(myvec == 0, FALSE, TRUE) # set 0 to FALSE, other values to TRUE



On Sun, Oct 30, 2011 at 3:50 PM, Alaios <alaios at yahoo.com> wrote:
> probably you mean
>
>
>
>
> For ?[?-indexing only: ?i?, ?j?, ?...? can be logical
> vectors, indicating elements/slices to select. ?Such vectors
> are recycled if necessary to match the corresponding extent.
> ?i?, ?j?, ?...? can also be negative integers, indicating
> elements/slices to leave out of the selection.
>
>
>
> How can i convert the positives to TRUE and zeros and FALSE?
>
>
>
> ________________________________
> From: William Dunlap <wdunlap at tibco.com>
>
> Sent: Sunday, October 30, 2011 9:17 PM
> Subject: RE: [R] why the a[-indx] does not work?
>
> ? > a[overLoadTesT==0]
> ? [1]? 2? 4? 5? 6? 7? 8? 9 10
> Look into help('[') or help('Subscript') to see
> how integer and logical (Boolean) subscripts differ.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios
>> Sent: Sunday, October 30, 2011 11:52 AM
>> To: R-help at r-project.org
>> Subject: [R] why the a[-indx] does not work?
>>
>> Dear all,
>>
>> Could you please explain me why
>>
>> > OverloadsTesT
>> [1] 1 0 1 0 0 0 0 0 0 0
>> > a<-matrix(data=seq(1,10),nrow=10)
>> > a
>> [,1]
>> [1,]? ? 1
>> [2,]? ? 2
>> [3,]? ? 3
>> [4,]? ? 4
>> [5,]? ? 5
>> [6,]? ? 6
>> [7,]? ? 7
>> [8,]? ? 8
>> [9,]? ? 9
>> [10,]? ?10
>> > a[-OverloadsTesT]
>> [1]? 2? 3? 4? 5? 6? 7? 8? 9 10
>>
>>
>>
>> the last line does not remove the first and third element and only does the first element.?
>>
>> What I want to do is for zeros to return the elements and for any positive value to remove it.
>> What I am doing wrong?
>>