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.
> 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 620The above code does not produce the output you show when I paste it into R. It would be highly desirable to have a short, documented, working example...> So the result CANDS is 103, 104 and 105 b/c the corresponding DEVS are > larger than the DEV(400 in this case).How do they correspond? Do you mean they are both columns of a data.frame as your example output suggests? But CANDS and DEVS are of differnt length, so this is probably not what you meant. Finally, your code seems to indicate that you want all elements of CANDS for which the corresponding (?) value of DEVS is less than threshold DEV, but only if DEV>DEVS. The latter produces a warning, as you are comparing a single value to a vector of 5, which is most likely not what you want. At this point my confusion is perfect and I give up. I think you need to give us a better explanantion of what data you have and what exactly you want to accomplish. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel
I greatly apoligize, clear in my own mind, just didnt explain well enough. DEVS should equal 6 values the last being 620, like the data frame: CANDS DEVS> [1,] 100 120 > [2,] 101 220 > [3,] 102 320 > [4,] 103 420 > [5,] 104 520 > [6,] 105 620And yes, my first question is do i need a "if" statement at all as the which command seems to do the same thing. IN my working code i start with a vector of Candidates, a process occurs that looks up a value associated with each of those Candidates. If the corresponding value is equal to or larger than the starting value, in the test case the DEV value, then that Candidate is kept and the next Candidate is analyzed. The final product is a new vector of Candidates, those that are equal to or larger than the DEV value. Hope i didnt further the perfection of your confucion. Thanks for your time, let me know if i need to ask a better question Cheers, JR Philipp Pagel-5 wrote:> > >> 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 > > > The above code does not produce the output you show when I > paste it into R. It would be highly desirable to have a short, > documented, working example... > >> So the result CANDS is 103, 104 and 105 b/c the corresponding DEVS are >> larger than the DEV(400 in this case). > > How do they correspond? Do you mean they are both columns of a > data.frame as your example output suggests? But CANDS and DEVS > are of differnt length, so this is probably not what you meant. > Finally, your code seems to indicate that you want all elements > of CANDS for which the corresponding (?) value of DEVS is less > than threshold DEV, but only if DEV>DEVS. The latter produces a > warning, as you are comparing a single value to a vector of 5, > which is most likely not what you want. At this point my > confusion is perfect and I give up. > > I think you need to give us a better explanantion of what data > you have and what exactly you want to accomplish. > > cu > Philipp > > > -- > Dr. Philipp Pagel > Lehrstuhl f?r Genomorientierte Bioinformatik > Technische Universit?t M?nchen > Wissenschaftszentrum Weihenstephan > 85350 Freising, Germany > http://mips.gsf.de/staff/pagel > > ______________________________________________ > R-help at 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. > >-- View this message in context: http://www.nabble.com/Conditionally-Removing-data-from-a-vector-tp20627244p20628349.html Sent from the R help mailing list archive at Nabble.com.