[R] Errors in if statement
arun
smartpink111 at yahoo.com
Sat Sep 29 03:13:39 CEST 2012
Hi,
Try this:
geno<-read.table(text="
P1 P2 P3 P4 P5
1 2 2 3 2
2 2 2 1 1
1 2 1 2 NA
NA 2 3 4 5
1 1 3 1 3
",sep="",header=TRUE,stringsAsFactors=FALSE)
geno1<-as.matrix(geno)
geno1[is.na(geno1)]<-0
tmp<-apply(geno1,1,function(x) ifelse((sum(x!=2)>3) & (sum(x==1)>=1) & (sum(x==3)>=1), 1,0) )
tmp
#[1] 0 0 0 0 1
A.K.
----- Original Message -----
From: JiangZhengyu <zhyjiang2006 at hotmail.com>
To:
Cc: r-help at r-project.org
Sent: Friday, September 28, 2012 4:16 PM
Subject: [R] Errors in if statement
Hi guys, I have many rows (>1000) and columns (>30) of "geno" matrix. I use the following loop and condition statement (adapted from someone else code). I always have an error below. I was wondering if anyone knows what's the problem & how to fix it.
Thanks,Zhengyu ########### geno matrix P1 P2 P3 P4
1 2 2 3 2
2 2 2 1 1
1 2 1 2 NANA 2 3 4 5 ###########
for(i in 1:4) {
cat(i,"")
if(sum(geno[i,]!=2)>3 && sum(geno[i,]==1)>=1 && sum(geno[i,]==3)>=1){
tmp = 1
}
} ########### 1 2 Error in if (sum(geno[i, ] != 2) > 3 && sum(geno[i, ] == 1) >= 1 && sum(geno[i, :
missing value where TRUE/FALSE needed
[[alternative HTML version deleted]]
______________________________________________
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