[R] Creating a vector based on lookup function

PDXRugger J_R_36 at hotmail.com
Wed Nov 26 19:32:22 CET 2008


I am still searching for a solution to what i think is a simple problem i am
having with building a vector in a for loop.  I have built a more
understandable example so hopefully that will help..help you, help me, if
you know what i mean.  

dev=400
#test location model TAZs to reference
cands=c(101,105,109)	

#Create Object of length of cands
candslength=length(cands)

#TEST TAZ Vector 
CANDS=(100:110)

#Test Dev Vector
TAZDEVS=c(120,220,320,420,520,620,720,820,920,1020,1120)

#Creates datframe of CANDS and DEVS
TAZLIST=data.frame(CANDS,TAZDEVS)

for(i in 1:candslength){
		
	cand=cands[i]	

	#Creates an object based on the value of "cands" in TAZLIST
	TAZDet=TAZLIST[TAZLIST$CANDS==cand[i],2]

	}

What i would like to see is TAZDet filled with the "cands" corresponding
values found in "TAZLIST"'s second column TAZDEVS, they would be
120,520,920.  So if things worked the way i would like them TAZDet would be
a vector containing these three values (102,520,920).  At this point it
gives me NAs.  Any help would be desirable, Thanks guys and gals.


Cheers, 
JR
-- 
View this message in context: http://www.nabble.com/Creating-a-vector-based-on-lookup-function-tp20706588p20706588.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list