[R] Conditionally Removing data from a vector

PDXRugger J_R_36 at hotmail.com
Fri Nov 21 19:38:19 CET 2008


I am having trouble removing entries from a vector based on the value of the
vector and another object value.  It works in my pseudo test run:

DEV=400	
#Y
CANDS=c(100:105)
#Z
DEVS=c(120,220,320,420,520)
	if(DEV>DEVS)
		 (CANDS=CANDS[which(DEV<DEVS)]) 
     CANDS DEVS
[1,]   100  120
[2,]   101  220
[3,]   102  320
[4,]   103  420
[5,]   104  520
[6,]   105  620

So the result  CANDS is 103, 104 and 105 b/c the corresponding DEVS are
larger than the DEV(400 in this case).
Now i am trying to implement this into my working code but it doenst seem to
work.  

#Loads TAZ and corresponding vacant acres data
TAZ_VAC_ACRES= read.csv(file="I:/Research.....csv",header=TRUE);

#Converts vacant acres by TAZ to vacant square footage by TAZ
TAZ_VAC_FEET=cbind(TAZ_VAC_ACRES[1],TAZ_VAC_ACRES[2]*43560)

#Creates test Candidates Vector
Candidates=c(100,101,102,103,104,105)

#Creates object equaling the number of candidate TAZs from the main script
Location Choice Model
NumCands1=length(Candidates)

Dev..At=9999999

	for(i in 1:NumCands1){	
	
	#Renames each candidate TAZ to function variable
	Loc_Mod_TAZ=Candidates[i]

	#Converts Development size from main script to Development density function
format
	Dev_Size=Dev..At

	#Determines vacant square feet by TAZ 
	TAZDetermine_FEET=TAZ_VAC_FEET[TAZ_VAC_FEET$TAZ==Loc_Mod_TAZ,2]
	
			#Determines if the Candidate TAZs have sufficient vacancy and creates
vector with TAZs that can accomadate development
			if(Dev_Size>TAZDetermine_FEET)
				(Candidates=Candidates[which(Dev_Size>TAZDetermine_FEET)])

	}

So basically i am starting out with a list of CAndidate TAZs and i want to
remove the TAZS that are not big enough to accomadate the
Development(Dev..At).  My test code works but again i cant get it to run in
my workiong code.  Anything stupid im missing or maybe a better approach
than the "which" function.  Remove only seem useful for entire objects so
not sure what else would work. Thanks guys and gals

Cheers, 
JR

-- 
View this message in context: http://www.nabble.com/Conditionally-Removing-data-from-a-vector-tp20627244p20627244.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list