[R] If then else with command for

Mestat mestat at pop.com.br
Tue Sep 14 19:29:34 CEST 2010


Hey listers,
I am trying to do something simple... Check the program below...
I would like to create a variable named COLOR according to the conditions
that I stablished... But the problem is that it seems that my variable COLOR
is checking just on sample, may be last in the loop... Certainly, I am
missing something...
Thanks in advance,
Marcio

x<-c(288,139,196,159,536,134,623,517,96,467,277,155,386,241,422,6263,612,532,250,412,339,55,290,249,164,97,74,144,1277,240,163,63,488,111,128,230,720,179,37,24,65,37,89,187,60,939,1008,81,310,58,169,38,68,190,78,807,220,226,69,179129,119,73,59,92,127,104,75,505,183,49,41,76,113,90,79,408,140,200,284,103,58,654,118,431,192,233,102,97,56,69,73,86,53,105,81,77,472,129,194,299,81,122,113,186,91,145,133,114,78,78,72,70,3471,641,275,815,149,185,172,240,67,526,122,229,298,317,179,233,66,129,87,82,63,65,72,6720,381,240,118,396,66,35,43,166,216,53,82,90,62,77,207,68,52,277,396,220,751,146,95,37,35,39,46,59,44,105,87,66,62,175,252,128,330,57,83,208,74,63,109,37,105,38,82,76,63,86,603,209,100,121,191,130,63,128,90,79,50,1025,121,87,309,75,189,36,82,84,60,132,46,965,155,132,219,112,53,90,66,100,77,52,60,100,153,418,392,76,130,197,262,49,105,87,70,147,720,342,233,203,249,92,134,231,782,184,182,432,49,63,94,124,69,53,91,451,53,21,42,50,40,32,58,26,28,61,60,35,764,105,592,55,28,46,34,123,41,54,207,64,562,295,226,63,233)
R<-142
color<-rep(0,142)
for(i in 1:R){  
x<-sample(x,142,replace=FALSE)
if (!3471 %in% x & !6263 %in% x & !6720 %in% x){color[i]<-1} else 
if (3471 %in% x & !6263 %in% x & !6720 %in% x){color[i]<-2} else 
if (!3471 %in% x & 6263 %in% x & !6720 %in% x){color[i]<-3} else 
if (!3471 %in% x & !6263 %in% x & 6720 %in% x){color[i]<-4} else 
if (3471 %in% x & 6263 %in% x & !6720 %in% x){color[i]<-5} else 
if (3471 %in% x & !6263 %in% x & 6720 %in% x){color[i]<-6} else 
if (!3471 %in% x & 6263 %in% x & 6720 %in% x){color[i]<-7} else 
if (3471 %in% x & 6263 %in% x & 6720 %in% x){color[i]<-8} else{color[i]<-0}
}

-- 
View this message in context: http://r.789695.n4.nabble.com/If-then-else-with-command-for-tp2539341p2539341.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list