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. (The issue of matrix versus dataframe was raised by someone else.) -- David.> 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]] > > ______________________________________________ > 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.David Winsemius Alameda, CA, USA
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 ? St?phane [[alternative HTML version deleted]]
> 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
> On 30 Mar 2015, at 09:59 , St?phane Adamowicz <stephane.adamowicz at avignon.inra.fr> wrote: > > > 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 ?The standard problem with T for TRUE is if T has been used for some other purpose, like a time variable. E.g., T <- 0 ; complete.cases(X)==T. complete.cases()==TRUE is just silly, like (x==0)==TRUE or ((x==0)==TRUE)==TRUE). (However, notice that x==TRUE is different from as.logical(x) if x is numeric, so ifelse(x,y,z) may differ from ifelse(x==TRUE,y,z).) -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com