[R] matrix manipulation question

Henric Winell nilsson.henric at gmail.com
Fri Mar 27 13:29:40 CET 2015


On 2015-03-27 11:41, Stéphane Adamowicz wrote:

> Well, it seems to work with me.
>
> Y <- as.matrix(airquality)
> head(Y, n=8)
>       Ozone Solar.R Wind Temp Month Day
> [1,]    41     190  7.4   67     5   1
> [2,]    36     118  8.0   72     5   2
> [3,]    12     149 12.6   74     5   3
> [4,]    18     313 11.5   62     5   4
> [5,]    NA      NA 14.3   56     5   5
> [6,]    28      NA 14.9   66     5   6
> [7,]    23     299  8.6   65     5   7
> [8,]    19      99 13.8   59     5   8
>
> Z <- Y[,complete.cases(t(Y))==T]

Peter's point, I guess, is that

1. complete.cases(t(Y)) is already a vector of logicals
2. T (and F) can be redefined, so what if T <- FALSE?


Henric Winell



>
> head(Z, n=8)
>       Wind Temp Month Day
> [1,]  7.4   67     5   1
> [2,]  8.0   72     5   2
> [3,] 12.6   74     5   3
> [4,] 11.5   62     5   4
> [5,] 14.3   56     5   5
> [6,] 14.9   66     5   6
> [7,]  8.6   65     5   7
> [8,] 13.8   59     5   8
>
> The columns that contained NA were deleted.
>
>
> Le 27 mars 2015 � 10:38, peter dalgaard <pdalgd at gmail.com> a �crit :
>
>>
>> On 27 Mar 2015, at 09:58 , St�phane Adamowicz <stephane.adamowicz at avignon.inra.fr> wrote:
>>
>>> data_no_NA <- data[, complete.cases(t(data))==T]
>>
>> Ouch! logical == TRUE is bad, logical == T is worse:
>>
>> data[, complete.cases(t(data))]
>>
>>
>> --
>> Peter Dalgaard, Professor,
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Office: A 4.23
>> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
> _________________________________
> St�phane Adamowicz
> Inra, centre de recherche Paca, unit� PSH
> 228, route de l'a�rodrome
> CS 40509
> domaine St Paul, site Agroparc
> 84914 Avignon, cedex 9
> France
>
> stephane.adamowicz at avignon.inra.fr
> tel.  +33 (0)4 32 72 24 35
> fax. +33 (0)4 32 72 24 32
> do not dial 0 when out of France
> web PSH  : https://www6.paca.inra.fr/psh
> web Inra : http://www.inra.fr/
> _________________________________
>
>
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list