[R] matrix manipulation question
Stéphane Adamowicz
stephane.adamowicz at avignon.inra.fr
Fri Mar 27 11:41:57 CET 2015
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]
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]]
More information about the R-help
mailing list