[R] Excluding all teh columns from a data frame if the standard deviation of that column is zero(0).

arun smartpink111 at yahoo.com
Tue Oct 16 14:04:18 CEST 2012



HI,
May be this helps. 

set.seed(1)
 dat1<-data.frame(col1=rep(5,10),col2=rnorm(10,15),col3=rep(25,10),col4=rnorm(10,25))
 dat1[sapply(dat1,function(x) sd(x)!=0)]
#       col2     col4
#1  14.37355 26.51178
#2  15.18364 25.38984
#3  14.16437 24.37876
#4  16.59528 22.78530
#5  15.32951 26.12493
#6  14.17953 24.95507
#7  15.48743 24.98381
#8  15.73832 25.94384
#9  15.57578 25.82122
#10 14.69461 25.59390
A.K.




----- Original Message -----
From: siddu479 <onlyfordigitalstuff at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, October 16, 2012 4:08 AM
Subject: [R] Excluding all teh columns from a data frame if the standard deviation of that column is zero(0).

Hi All,

  I have a data frame where nearly 10K columns of data, where most of them
have standard deviation( of all rows) as zero.
I want to exclude all the columns from the data frame and proceed to further
processing.

I tried like blow.  
*data <- read.csv("data.CSV", header=T)

for(i in 2:ncol(data))
if(sd(data[,i])==0){
df[,i] <-NULL
}
*
where I have the data columns from 2:ncol, but getting the error "Error in
df[, i] <- NULL : object of type 'closure' is not subsettable"

Can any one suggest the right method to accomplish this.






-----
Sidda
Business Analyst Lead
Applied Materials Inc.

--
View this message in context: http://r.789695.n4.nabble.com/Excluding-all-teh-columns-from-a-data-frame-if-the-standard-deviation-of-that-column-is-zero-0-tp4646310.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at 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.





More information about the R-help mailing list