Dear friends I have an array consist of r-rows and c-columns e.g. x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1=array(x, dim=c(4,6)) output is> x1[,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 0 0 [2,] 1 2 3 4 0 0 [3,] 1 2 3 4 0 0 [4,] 1 2 3 4 0 0 How can i ignore columns having zero sums? Help in this regard is needed. Thanks M.Azam [[alternative HTML version deleted]]
Dimitris Rizopoulos
2008-Oct-14 08:10 UTC
[R] request: How to ignore columns having zero sums
try this: x <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1 <- array(x, dim=c(4,6)) ind <- colSums(x1) != 0 x1[, ind] I hope it helps. Best, Dimitris Muhammad Azam wrote:> Dear friends > I have an array consist of r-rows and c-columns e.g. > x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); > x1=array(x, dim=c(4,6)) > output is >> x1 > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 1 2 3 4 0 0 > [2,] 1 2 3 4 0 0 > [3,] 1 2 3 4 0 0 > [4,] 1 2 3 4 0 0 > How can i ignore columns having zero sums? Help in this regard is needed. Thanks > > > M.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 Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
Dear Dimitris Thanks a lot. ----- Original Message ---- From: Dimitris Rizopoulos <d.rizopoulos@erasmusmc.nl> To: Muhammad Azam <mazam72@yahoo.com> Cc: R Help <r-help@r-project.org> Sent: Tuesday, October 14, 2008 10:10:54 AM Subject: Re: [R] request: How to ignore columns having zero sums try this: x <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1 <- array(x, dim=c(4,6)) ind <- colSums(x1) != 0 x1[, ind] I hope it helps. Best, Dimitris Muhammad Azam wrote:> Dear friends > I have an array consist of r-rows and c-columns e.g. > x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); > x1=array(x, dim=c(4,6)) > output is >> x1 > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 1 2 3 4 0 0 > [2,] 1 2 3 4 0 0 > [3,] 1 2 3 4 0 0 > [4,] 1 2 3 4 0 0 > How can i ignore columns having zero sums? Help in this regard is needed. Thanks > > > M.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 Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 [[alternative HTML version deleted]]
Jorge Ivan Velez
2008-Oct-14 11:52 UTC
[R] request: How to ignore columns having zero sums
Dear Muhammad, Try also x <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1 <- array(x, dim=c(4,6)) x1[,apply(x1,2,function(x) !all(x==0))] HTH, Jorge On Tue, Oct 14, 2008 at 4:02 AM, Muhammad Azam <mazam72@yahoo.com> wrote:> Dear friends > I have an array consist of r-rows and c-columns e.g. > x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); > x1=array(x, dim=c(4,6)) > output is > > x1 > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 1 2 3 4 0 0 > [2,] 1 2 3 4 0 0 > [3,] 1 2 3 4 0 0 > [4,] 1 2 3 4 0 0 > How can i ignore columns having zero sums? Help in this regard is needed. > Thanks > > > M.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. >[[alternative HTML version deleted]]
Dear Jorge Thanks a lot. ----- Original Message ---- From: Jorge Ivan Velez <jorgeivanvelez@gmail.com> To: Muhammad Azam <mazam72@yahoo.com> Cc: R mailing list <r-help@r-project.org> Sent: Tuesday, October 14, 2008 1:52:15 PM Subject: Re: [R] request: How to ignore columns having zero sums Dear Muhammad, Try also x <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1 <- array(x, dim=c(4,6)) x1[,apply(x1,2,function(x) !all(x==0))] HTH, Jorge On Tue, Oct 14, 2008 at 4:02 AM, Muhammad Azam <mazam72@yahoo.com> wrote: Dear friends I have an array consist of r-rows and c-columns e.g. x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1=array(x, dim=c(4,6)) output is> x1[,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 0 0 [2,] 1 2 3 4 0 0 [3,] 1 2 3 4 0 0 [4,] 1 2 3 4 0 0 How can i ignore columns having zero sums? Help in this regard is needed. Thanks M.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. [[alternative HTML version deleted]]