Displaying 1 result from an estimated 1 matches for "combinn".
Did you mean:
combine
2010 Oct 07
2
Need help for loop code, thanks
...5.0
2 a 5.3
What I want to do is to get the max value of V3 for each unique V2 in each
V1. For example, when V1=1, unique V2 is (a, b, c, d), and corresponding max
value of V3 is (7.0, 2.0, 5.5, 6.0). And V1=2, unique V2 is (f, g, c, a) and
max value of V3 is (4.0, 4.6, 5.0, 5.3). Then combinne these max values.
My code is like:
z<-NULL
x<-NULL;y<-NULL
for (j in 1:2)
{
x<-unique(V2[V1==j])
for (i in 1:length(x))
{
y[i]<-max(V3[V2==x[i] & V1==j])
}
z<-c(z,y)
}
length(z)
My problem is the length of z is much bigger than the length of I'm su...