[R] matrix manipulation question

Berend Hasselman bhh at xs4all.nl
Mon Mar 30 10:36:35 CEST 2015


> On 30-03-2015, at 09:59, Stéphane Adamowicz <stephane.adamowicz at avignon.inra.fr> wrote:
> 
> 
> Le 27 mars 2015 à 18:01, David Winsemius <dwinsemius at comcast.net> a écrit :
> 
>> 
>> On Mar 27, 2015, at 3:41 AM, Stéphane Adamowicz wrote:
>> 
>>> Well, it seems to work with me.
>>> 
>> 
>> No one is doubting that it worked for you in this instance. What Peter D. was criticizing was the construction :
>> 
>> complete.cases(t(Y))==T
>> 
>> ... and it was on two bases that it is "wrong". The first is that `T` is not guaranteed to be TRUE. The second is that the test ==T (or similarly ==TRUE) is completely unnecessary because `complete.cases` returns a logical vector and so that expression is a waste of time.
>> 
> 
> Indeed, You are right, the following code was enough :
> «  Z <- Y[, complete.cases(t(Y) ] »
> 
> 
> However, in order to help me understand, would you be so kind as to give me a matrix or data.frame example where « complete.cases(X)== T » or « complete.cases(X)== TRUE » would give some unwanted result ?

T can be redefined.
Try this in your example with airquality:

T <- "hello"
Z <- Y[,complete.cases(t(Y))==T]
Z

TRUE is a reserved word and cannot be changed. But why use ==TRUE if not necessary?
All of this mentioned already by David Winsemius in a previous reply.

Berend



More information about the R-help mailing list