Error: (subscript) logical subscript too long

Posted by frespider on Stack Overflow See other posts from Stack Overflow or by frespider
Published on 2012-09-18T15:00:45Z Indexed on 2012/09/18 15:38 UTC
Read the original article Hit count: 824

Filed under:

Can some one let me know why I am getting this error and how I can fix it?

Here is the code

What I am trying to do is remove the rows that associated 1's if the column of that one's less than 10

a0=rep(1,40)
a=rep(0:1,20)
b=c(rep(1,20),rep(0,20))
c0=c(rep(0,12),rep(1,28))
c1=c(rep(1,5),rep(0,35))
c2=c(rep(1,8),rep(0,32))
c3=c(rep(1,23),rep(0,17))
c4=c(rep(1,6),rep(0,34))
x=matrix(cbind(a0,a,b,c0,c1,c2,c3,c4),nrow=40,ncol=8)
nam <- paste("V",2:9,sep="")
colnames(x)<-nam
dat <- cbind(y=rnorm(40,50,7),x)
#===================================
toSum <- colSums(dat)
Col <- Val <- NULL
for(i in 1:length(toSum)){
if(toSum[i]<10){
Col <- c(Col,colnames(dat)[i])
Val <- c(Val,toSum[i])}
}
cs <- colSums(dat) < 10
indx <- dat[,which(cs)]==0
for(i in 1:dim(indx)[2]){
datnw <- dat[indx[,i],]
dat <- datnw}
datnw2 <- dat[, -which(cs)]

Thanks

© Stack Overflow or respective owner

Related posts about r