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

2012-05-31 Thread arun
Remove columns from dataframe based on their statistics 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

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