Try this:

q <- z[match(p, y)]

Jean


`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA
715-627-4317, ext. 3125  (Office)
715-216-8014  (Cell)
715-623-6773  (FAX)
http://www.glsc.usgs.gov  (GLSC web site)
http://profile.usgs.gov/jvadams  (My homepage)
jvadams@usgs.gov  (E-mail)




From:
testrider <testrider@gmail.com>
To:
r-help@r-project.org
Date:
08/04/2011 07:21 AM
Subject:
[R] R loop problem
Sent by:
r-help-bounces@r-project.org



I have run into a speed issue, and given the size of the problem it feels
like there should be an easy solution. Here is the problem statement with
some arbitrary numbers added.

#p,q: vector with length(q)==length(p)==10000 and length(levels(p))==3000
#y,z: vectors with length(levels(y))=length(y)==length(z)==5000

for (i in levels(p)){
q[i==p]<-z[i==y]}

At first i used two for loops which was horrible, now i got rid of one but 
i
don't know how to lose the second one.


PS. I expect the solution to be available through google etc and I have
searched for a solution but i did not find any usefull websites, probably
because i cannot pinpoint the best search words.

--
View this message in context: 
http://r.789695.n4.nabble.com/R-loop-problem-tp3718103p3718103.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



	[[alternative HTML version deleted]]

