[R] More than on loop??

che fadialnaji at live.com
Mon Jan 25 00:14:10 CET 2010


Really thanks very much, with your help i was able to write a prober code to
count the aminoacids in all the cleaved and noncleaved and then to display
the results in a matrix with 8 column, i used only two loops instead of
three. The code is working but i still have warning telling me that: 
 “In if (x$Label[i] == nc) { ... :
  the condition has length > 1 and only the first element will be used)”
So please can you help me with this warning what is the reason of it as i
can’t understand exactly what does it mean? 
Here is the code that i am using, and the data file is attached:
x<-read.table("C:/Uni/502/CA2/hiv.dat", header=TRUE)
num<-nrow(x)
AA<-c('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y')
nc<-x$Label[61:308]
c<-x$Label[nc]
noncleaved<-function(x)
{
y<-matrix(0,20,8)
colnames(y)<-c("N4","N3","N2","N1","C1","C2","C3","C4")
for(i in 1:num){
if (x$Label[i]==nc)
{
for(j in 1:8){
res<-which(AA==substr(x$Peptide[i],j,j))
y[res, j]=y[res, j]+1
}
}
}
return (y/274*100)
}
cleaved<-function(x)
{
y<-matrix(0,20,8)
colnames(y)<-c("N4","N3","N2","N1","C1","C2","C3","C4")
for(i in 1:num){
if (x$Label[i]==c)
{
for(j in 1:8){
res<-which(AA==substr(x$Peptide[i],j,j))
y[res, j]=y[res, j]+1
}
}
}
return (y/113*100)
}
   
http://n4.nabble.com/file/n1288922/hiv.dat hiv.dat 
-- 
View this message in context: http://n4.nabble.com/More-than-on-loop-tp1015851p1288922.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list