Hi,
sapply(colnames(m)[-ncol(m)],function(i) {x1<-cbind(m[,i],m[,ncol(m)]);
length(which(x1[,1]!=0 & x1[,2]!=0))})
#A B C
#2 1 2
A.K.
- Original Message -
From: Hermann Norpois
To: r-help
Cc:
Sent: Friday, June 14, 2013 3:51 PM
Subject: [R] combination of columns in a
Hello,
I have a matrix m and I want to know how often does 1 (or !0) simultanously
appear in A and REF, B and REF, C and REF.
So actually I wish to automate following expression:
> length (which (m[,1]!=0&m[,4]!=0))
[1] 2
> length (which (m[,2]!=0&m[,4]!=0))
[1] 1
Thanks
Hermann
> m
A B C
2 matches
Mail list logo