[R] request: How to get column name

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Wed Sep 3 15:54:08 CEST 2008


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))

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 at 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



More information about the R-help mailing list