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]
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
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,
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
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]
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
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
__
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]
>
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
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
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
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
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
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 <
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
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
21 matches
Mail list logo