An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080903/34670a6d/attachment.pl>
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:
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080903/b3685066/attachment.pl>
r-help-bounces at 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) 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 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
______________________________________________ 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.
On 9/3/2008 11:05 AM, Petr PIKAL wrote:
r-help-bounces at 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
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 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 ______________________________________________ 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. ______________________________________________ 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.
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
on 09/03/2008 10:34 AM Chuck Cleland wrote:
On 9/3/2008 11:05 AM, Petr PIKAL wrote:
r-help-bounces at 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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080903/009b2d0e/attachment.pl>
r-help-bounces at r-project.org napsal dne 03.09.2008 17:34:24:
On 9/3/2008 11:05 AM, Petr PIKAL wrote:
r-help-bounces at 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:
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
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 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 ______________________________________________ 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. ______________________________________________ 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.
-- 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 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.