Re: [R] Remove columns from dataframe based on their statistics

2012-05-31 Thread arun
HI, I tweaked the code of James a little bit to produce the same result. > for(i in seq(ncol(df),1))  if(sd(df[,i])==0){  df[,i] <-NULL  } - Original Message - From: J Toll To: Johannes Radinger Cc: R-help@r-project.org Sent: Thursday, May 31, 2012 9:52 AM Subject: Re: [R]

Re: [R] Remove columns from dataframe based on their statistics

2012-05-31 Thread Jorge I Velez
ave to think about this > > /Johannes > > Original-Nachricht > > Datum: Thu, 31 May 2012 09:20:27 -0500 > > Von: J Toll > > An: Johannes Radinger > > CC: R-help@r-project.org > > Betreff: Re: [R] Remove columns from dataframe base

Re: [R] Remove columns from dataframe based on their statistics

2012-05-31 Thread Johannes Radinger
exept for column with name "B". I have to think about this /Johannes Original-Nachricht > Datum: Thu, 31 May 2012 09:20:27 -0500 > Von: J Toll > An: Johannes Radinger > CC: R-help@r-project.org > Betreff: Re: [R] Remove columns from dataframe based on their

Re: [R] Remove columns from dataframe based on their statistics

2012-05-31 Thread J Toll
On Thu, May 31, 2012 at 8:52 AM, J Toll wrote: > for (i in seq(ncol(df), 1)) >  if (length(unique(df[, i])) == 1) { >  df[, i] <- NULL > } Here's a similar method employing a more functional approach: df[, apply(df, 2, function(x) length(unique(x)) > 1)] James ___

Re: [R] Remove columns from dataframe based on their statistics

2012-05-31 Thread Jorge I Velez
Hi Johannes, Try df[, !apply(df, 2, function(x) sd(x, na.rm = TRUE) < 1e-10)] HTH, Jorge.- On Thu, May 31, 2012 at 9:27 AM, Johannes Radinger <> wrote: > Hi, > > I have a dataframe and want to remove columns from it > that are populated with a similar value (for the total > column) (the varia

Re: [R] Remove columns from dataframe based on their statistics

2012-05-31 Thread J Toll
On Thu, May 31, 2012 at 8:27 AM, Johannes Radinger wrote: > Hi, > > I have a dataframe and want to remove columns from it > that are populated with a similar value (for the total > column) (the variation of that column is 0). Is there an > easier way than to calculate the statistics and then > rem

[R] Remove columns from dataframe based on their statistics

2012-05-31 Thread Johannes Radinger
Hi, I have a dataframe and want to remove columns from it that are populated with a similar value (for the total column) (the variation of that column is 0). Is there an easier way than to calculate the statistics and then remove them by hand? A <- runif(100) B <- rep(1,100) C <- rep(2.42,100) D

Re: [R] Remove columns

2009-08-18 Thread Paul Hiemstra
Hi, This line of code does the trick: a[,which(apply(a, 2, sum) != 0)] cheers, Paul Alberto Lora M wrote: Hi Everbody Could somebody help me.? I need to remove the columns where the sum of it components is equal to zero. For example a<-matrix(c(0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,1,

Re: [R] Remove columns

2009-08-18 Thread baptiste auguie
Try this, a[ ,as.logical(colSums(a))] mind an unfortunate logical vs integer indexing trap: isTRUE(all.equal( a[ ,!!colSums(a)] , a[ ,colSums(a)] )) [1] FALSE HTH, baptiste 2009/8/18 Alberto Lora M : > Hi Everbody > > Could somebody help me.? > > I need to remove the columns where the sum o

Re: [R] Remove columns

2009-08-18 Thread Steve Lianoglou
Hi Alberto, On Aug 18, 2009, at 4:14 AM, Alberto Lora M wrote: Hi Everbody Could somebody help me.? I need to remove the columns where the sum of it components is equal to zero. For example a<-matrix(c(0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,1,0,0,1,0), ncol=4) a [,1] [,2] [,3] [,4]

[R] Remove columns

2009-08-18 Thread Alberto Lora M
Hi Everbody Could somebody help me.? I need to remove the columns where the sum of it components is equal to zero. For example > a<-matrix(c(0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,1,0,0,1,0), ncol=4) > a [,1] [,2] [,3] [,4] [1,]0001 [2,]0101 [3,]00

Re: [R] remove columns containing all zeros (or other value)

2009-01-15 Thread Jim Lemon
How about: remove.constant.values<-function(x,MARGIN,value2remove) { is.constant.line<-function(x,value2remove) { return(any(x!=value2remove)) } return(unlist(apply(x,MARGIN,is.constant.line,value2remove))) } x[,remove.constant.values(x,2,0)] Jim __

Re: [R] remove columns containing all zeros (or other value)

2009-01-14 Thread andrew
or this x[,!(colSums(abs(x)) == 0)] On Jan 15, 10:00 am, Marc Schwartz wrote: > Careful: > > x <- matrix(c(1, 5, 3, 2, 1, 4, -1, 0, 1), >             ncol = 3, nrow = 3) > > > x > >      [,1] [,2] [,3] > [1,]    1    2   -1 > [2,]    5    1    0 > [3,]    3    4    1 > > > x[, colSums(x) != 0] >

Re: [R] remove columns containing all zeros (or other value)

2009-01-14 Thread Marc Schwartz
Careful: x <- matrix(c(1, 5, 3, 2, 1, 4, -1, 0, 1), ncol = 3, nrow = 3) > x [,1] [,2] [,3] [1,]12 -1 [2,]510 [3,]341 > x[, colSums(x) != 0] [,1] [,2] [1,]12 [2,]51 [3,]34 Not quite the result wanted... :-) Try th

Re: [R] remove columns containing all zeros (or other value)

2009-01-14 Thread Gustavo Carvalho
Sorry for the double post, but this is probably faster: x[, colSums(x) != 0] On Wed, Jan 14, 2009 at 8:22 PM, Gustavo Carvalho wrote: > You can also try this: > > x[,-(which(colSums(x) == 0))] > > Cheers, > > Gustavo. > > On Wed, Jan 14, 2009 at 8:01 PM, Anthony Dick wrote: >> Hello- >> >> I wo

Re: [R] remove columns containing all zeros (or other value)

2009-01-14 Thread Gustavo Carvalho
You can also try this: x[,-(which(colSums(x) == 0))] Cheers, Gustavo. On Wed, Jan 14, 2009 at 8:01 PM, Anthony Dick wrote: > Hello- > > I would like to remove the columns of a matrix that contain all zeros. For > example, from > x<-matrix(c(1,5,3,2,1,4,0,0,0), ncol=3,nrow=3) > > I would like t

Re: [R] remove columns containing all zeros (or other value)

2009-01-14 Thread Jorge Ivan Velez
Hi Anthony, Try this: x[,apply(x,2,function(x) !all(x==0))] HTH, Jorge On Wed, Jan 14, 2009 at 5:01 PM, Anthony Dick wrote: > Hello- > > I would like to remove the columns of a matrix that contain all zeros. For > example, from > x<-matrix(c(1,5,3,2,1,4,0,0,0), ncol=3,nrow=3) > > I would l

[R] remove columns containing all zeros (or other value)

2009-01-14 Thread Anthony Dick
Hello- I would like to remove the columns of a matrix that contain all zeros. For example, from x<-matrix(c(1,5,3,2,1,4,0,0,0), ncol=3,nrow=3) I would like to remove the third column. However, because this is in a loop I need a way to first determine which columns are all zeros, and only the

Re: [R] Remove Columns by Name from zoo object

2008-11-10 Thread Sean Carmody
Perfect, works like a charm. Thanks Gabor. Sean. On Mon, Nov 10, 2008 at 11:35 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On Mon, Nov 10, 2008 at 12:31 AM, Sean Carmody <[EMAIL PROTECTED]> wrote: >> The tricks for removing columns specified by name from data frames such as >> >> x$mycol <

Re: [R] Remove Columns by Name from zoo object

2008-11-10 Thread Gabor Grothendieck
On Mon, Nov 10, 2008 at 12:31 AM, Sean Carmody <[EMAIL PROTECTED]> wrote: > The tricks for removing columns specified by name from data frames such as > > x$mycol <- NULL That only works for data frames since they are based on lists but not for objects like matrix, ts and zoo which are not based o

[R] Remove Columns by Name from zoo object

2008-11-09 Thread Sean Carmody
The tricks for removing columns specified by name from data frames such as x$mycol <- NULL (and others described here http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:remove_columns_by_name) do not seem to work for a zoo object. Any suggestions as to how to do this, or is my best bet