Or:

which(apply(x == 0, 2, all))

On Wed, Sep 3, 2008 at 12:46 PM, Marc Schwartz <marc_schwartz@comcast.net>wrote:

> on 09/03/2008 10:34 AM Chuck Cleland wrote:
> > On 9/3/2008 11:05 AM, Petr PIKAL wrote:
> >> r-help-bounces@r-project.org 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
> >
>
> Another (column-wise) approach to this would be:
>
> x <- c(3,3,3,3,0,0,0,0,5,5,5,5,8,8,8,8)
> x <- matrix(x, nrow=4)
>
> > which(apply(x, 2, function(i) all(i == 0)))
> [1] 2
>
>
> x <- c(3,3,3,3,1,-1,1,-1,5,5,5,5,8,8,8,8)
> x <- matrix(x, nrow=4)
>
> > which(apply(x, 2, function(i) all(i == 0)))
> integer(0)
>
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

