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
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
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
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
___
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
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
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
7 matches
Mail list logo