[R] Simple For Loop Help
arun.gurubaramurugeshan
arun.gurubaramurugeshan at Autozone.com
Thu Mar 29 23:32:48 CEST 2012
Hi,
I need help with the following.
I have a dataset Y with 200 observations and three variables Y1, Y2 & Y3. I
have to find the minimum of Y1, Y2 & Y3 and if the minimum is Y1 then I have
to assign 1 to a variable (Y4), if Y2 is the minimum then "2" to Y4 else
"3" to Y4. This is what I have done....
for (i in 1:200) if(Y1<Y2 & Y1<Y3) Y$Y4=1 else if (Y2<Y3) Y$Y4=2
else Y$Y4=3
and R is throwing back this warning message
Warning messages:
1: In if (Y1 < Y2 & Y1 < Y3) Y4 <- 1 else if (Y2 < Y3) Y4
<- 2 else Y4 <- 3 :
the condition has length > 1 and only the first element will be used
2: In if (Y2 < Y3) Y4 <- 2 else Y4 <- 3 :
the condition has length > 1 and only the first element will be used
Any help would be appreciated.
Thanks
Arun
--
View this message in context: http://r.789695.n4.nabble.com/Simple-For-Loop-Help-tp4517088p4517088.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list