Hi James Hi Jorge, Thank you very much! I like the apply-approach, it seems really quite simple and I get back the TRUE-FALSE vector which I can use for indexing the dataframe. Now there popped the questions if one can implement any "exeption", like do the selection of the columns 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 <jct...@gmail.com> > An: Johannes Radinger <jradin...@gmx.at> > CC: R-help@r-project.org > Betreff: Re: [R] Remove columns from dataframe based on their statistics > On Thu, May 31, 2012 at 8:52 AM, J Toll <jct...@gmail.com> 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 -- Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a ______________________________________________ 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.