[R] indeterminate for loop
lm609 at york.ac.uk
lm609 at york.ac.uk
Tue Mar 15 16:19:28 CET 2011
Thanks! I've never come across 'while' before and it's perfect.
On Mar 15 2011, Jonathan P Daily wrote:
>?"while"
>You don't want a for loop. You need a while loop.
>--------------------------------------
>Jonathan P. Daily
>Technician - USGS Leetown Science Center
>11649 Leetown Road
>Kearneysville WV, 25430
>(304) 724-4480
>"Is the room still a room when its empty? Does the room,
> the thing itself have purpose? Or do we, what's the word... imbue it."
> - Jubal Early, Firefly
>
>r-help-bounces at r-project.org wrote on 03/15/2011 10:14:21 AM:
>
>> [image removed]
>>
>> [R] indeterminate for loop
>>
>> lm609
>>
>> to:
>>
>> r-help
>>
>> 03/15/2011 10:16 AM
>>
>> Sent by:
>>
>> r-help-bounces at r-project.org
>>
>> Hello,
>>
>> I have written a 'for' loop which on the first run makes nearest
>neighbour
>> calculations for my dataset 'A' in relation to dataset 'B', then based
>on
>> these results, some of the rows from A are moved into dataset B, and the
>
>> calculation is repeated on the remaining rows in A. Therefore a smaller
>and
>> smaller amount of data is analysed as the loop proceeds, since A is
>losing
>> rows each time. The results of the calculation change as less data is
>used,
>> but not in a predictable way, therefore the end point of the loop is
>> indeterminate.
>>
>> The script is long and the datasets big, but a simplified example where
>'A'
>> and 'B' are datasets, and the function 'ndist2' calculates 'x' is...
>>
>> for (i in 1:100)
>> {
>> C <- data.frame(ndist2(B,A))
>> C1 <- subset(C, x = min(C$x))
>> B <- rbind(B, C1)
>> A <- subset(C, x > min(C$x))
>> }
>>
>> So eventually A runs out.
>>
>> Currently, I let the loop run until a warning comes up which effectively
>
>> says no more data, and at this point it is finished.
>>
>> What I would now like to do is place this loop inside another loop in
>order
>> to run through multiple datasets, but I can't do this when the script
>> produces a warning message at the end of each dataset.
>>
>> Is there any way I can overcome this problem?
>>
>> Thanks for your help,
>> Louise
>>
>> ______________________________________________
>> 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.
>
>
More information about the R-help
mailing list