Skip to content
Back to formatted view

Raw Message

Message-ID: <1320002414631-3953815.post@n4.nabble.com>
Date: 2011-10-30T19:20:14Z
From: David Winsemius
Subject: why the a[-indx] does not work?
In-Reply-To: <4EADA172.6060100@gmail.com>

Duncan Murdoch-2 wrote:
> 
> On 11-10-30 2:52 PM, Alaios wrote:
>> 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?
> 
> You are asking it to remove item 1, and it does.  If you want to negate 
> a logical vector, you need to use a logical vector and negate it, e.g.
> 
> OverloadsTesT <- as.logical(OverloadsTeSt)
> a[!OverloadsTest]
> 
> Duncan Murdoch
> 
> 

Or:

a[-c(1,3)]

-- 
David.

--
View this message in context: http://r.789695.n4.nabble.com/why-the-a-indx-does-not-work-tp3953737p3953815.html
Sent from the R help mailing list archive at Nabble.com.