Skip to content

request: How to get column name

8 messages · Muhammad Azam, Dimitris Rizopoulos, Jorge Ivan Velez +4 more

#
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:

  
    
#
r-help-bounces at r-project.org napsal dne 03.09.2008 15:54:08:
Isn't this the same?

which(colSums(x)==0)

Regards
Petr
all of
"2". How
http://www.R-project.org/posting-guide.html
http://www.R-project.org/posting-guide.html
#
On 9/3/2008 11:05 AM, Petr PIKAL wrote:
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)
integer(0)
[1] 2

  
    
#
on 09/03/2008 10:34 AM Chuck Cleland wrote:
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)
[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)
integer(0)


HTH,

Marc Schwartz
#
r-help-bounces at r-project.org napsal dne 03.09.2008 17:34:24:
zero:
OK you got me.
What about

which(colSums(abs(x))==0)

and yes, I am aware of floating point arithmetic, so better approach would 
be

which(colSums(abs(x))<some.small.value)

Regards
Petr
http://www.R-project.org/posting-guide.html
http://www.R-project.org/posting-guide.html