Dr. Petris,
Thank you so much for your help. I appreciate it. I am still learning R!
Thanks
Arun
--
View this message in context:
http://r.789695.n4.nabble.com/Simple-For-Loop-Help-tp4517088p4519056.html
Sent from the R help mailing list archive at Nabble.com.
_
Hi Arun,
This seems to do what you are looking for:
Y <- matrix(rnorm(12), 4, 3)
Y
[,1] [,2][,3]
[1,] -1.0457177 0.7756343 -0.06063478
[2,] -0.8962113 1.5573704 -0.50137832
[3,] 1.2693872 -0.3654018 0.92606273
[4,] 0.5938409 0.8165564 0.03693769
X <- apply(Y,
tyr this:
> # generate some data
> x <- cbind(y1 = runif(100)
+ , y2 = runif(100)
+ , y3 = runif(100)
+ )
>
> x <- cbind(x, y4 = apply(x, 1, which.min))
> x
y1y2 y3 y4
[1,] 0.976953289 0.91072645970 0.713624001 3
[2,] 0.630992512
On Thu, Mar 29, 2012 at 4:32 PM, arun.gurubaramurugeshan
wrote:
> 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), i
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
5 matches
Mail list logo