On 9/3/2008 11:05 AM, Petr PIKAL wrote: > [EMAIL PROTECTED] napsal dne 03.09.2008 15:54:08: > >> try this: >> >> x <- c(3,3,3,3,0,0,0,0,5,5,5,5,8,8,8,8) >> x <- matrix(x, nrow=4) >> >> which(colSums(x == 0) == nrow(x)) > > Isn't this the same? > > which(colSums(x)==0)
No, because the column sum can be zero without each element being zero: x <- c(3,3,3,3,1,-1,1,-1,5,5,5,5,8,8,8,8) x <- matrix(x, nrow=4) > which(colSums(x == 0) == nrow(x)) integer(0) > which(colSums(x)==0) [1] 2 > Regards > Petr > >> I hope it helps. >> >> Best, >> Dimitris >> >> >> Muhammad Azam wrote: >>> Dear R community >>> I have a problem regarding which of the column in a matrix contains > all of >> zero elements. e.g. >>> x=c(3,3,3,3,0,0,0,0,5,5,5,5,8,8,8,8); x=matrix(x, nrow=4) >>> the output is >>> >>>> x >>>> >>> [,1] [,2] [,3] [,4] >>> [1,] 3 0 5 8 >>> [2,] 3 0 5 8 >>> [3,] 3 0 5 8 >>> [4,] 3 0 5 8 >>> In this case the required column is second so the result should be > "2". How >> can i get it? >>> >>> best regards >>> >>> Muhammad Azam >>> >>> >>> >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> 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. >>> >>> >> >> -- >> Dimitris Rizopoulos >> Assistant Professor >> Department of Biostatistics >> Erasmus University Medical Center >> >> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands >> Tel: +31/(0)10/7043399 >> Fax: +31/(0)10/7044657 >> >> ______________________________________________ >> R-help@r-project.org mailing list >> 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. > > ______________________________________________ > R-help@r-project.org mailing list > 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. > -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 ______________________________________________ R-help@r-project.org mailing list 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.