COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### setting corresponding values to zero

• Follow

```Hi....

I've done measurements over time...for each single time I have two corresponding values x, y.

I want to set the y to zero, if x does not repeat istself during some consecutive time....
let say
t     x   y
1    2   8
1    5   3
2    1   7
3    3   3
3    5   2
3    8   1
4    2   1
4    3   10
5    1   8
5    2   7
6    1   8

Imagine that data should repeat itself at least every two measurements, then the limit<=2, and if it is already appeared before, the corresponding data shall stand there. then the output shall be:
t     x   y
1    2   0
1    5   3
2    1   0
3    3   3
3    5   2
3    8   0
4    2   0
4    3   10
5    1   8
5    2   7
6    1   8

I appreciate your help, on any advise that, how I can manipulate the data to get the desired output.
```
 0

```On 12/11/2011 4:43 PM, SM wrote:
> Hi....
>
> I've done measurements over time...for each single time I have two corresponding values x, y.
>
> I want to set the y to zero, if x does not repeat istself during some consecutive time....
> let say
> t     x   y
> 1    2   8
> 1    5   3
> 2    1   7
> 3    3   3
> 3    5   2
> 3    8   1
> 4    2   1
> 4    3   10
> 5    1   8
> 5    2   7
> 6    1   8
>
> Imagine that data should repeat itself at least every two measurements, then the limit<=2,
>and if it is already appeared before, the corresponding data shall stand there.
>then the output shall be:
> t     x   y
> 1    2   0
> 1    5   3
> 2    1   0
> 3    3   3
> 3    5   2
> 3    8   0
> 4    2   0
> 4    3   10
> 5    1   8
> 5    2   7
> 6    1   8
>
> I appreciate your help, on any advise that, how I can manipulate the data to
>get the desired output.

Are you looking for a 'clever' way to do this? If not,
why not simply do the brute force method:

Starting scanning, for each element, scan the list ahead to see if the
current 'x' element matches the condition to make its 'y' become '0' or
not. Repeat this process for each element.  So, roughly O(n^2) order in
time.

First get it working right, then start looking for improvements if the
performance is not satisfactory.

hth,

--Nasser

```
 0

```Why for times 5 did the y not get set to zero like it did for the 4
times?  You set one of the 4 rows to have a y of zero but not one of
the 5 rows.  x did not repeat for the 5's yet your output shows no y
that equals zero.  So I don't understand your criteria.  I also don't
understand the grammar or meaning of "then the limit<=2, and if it is
already appeared before, the corresponding data shall stand there."
What do you mean by "then the limit <=2"???
```
 0
Reply imageanalyst (7590) 12/13/2011 2:07:10 AM

2 Replies
37 Views