mercredi 7 décembre 2016

R algorithm for deleting rows with artefacts

I'm analyzing DEM data of rivers with R and need assistance with the data processing. The DEM data include many artifacts, where the river longitudinal profile goes slightly uphill, which is in fact nonsense. So I would like to have an algorithm to delete all rows from the data set where the Z value (elevation) is higher than the predecessor. To explain it better, just look at the following data rows:

*data.frame*

ID Z

1  105.2

2  105.4

3  105.3

4  105.1

5  105.1

6  105.2

7  104.9

I would like to delete rows 2, 3 and 6 from the list. I wrote the following code but it doesn't work:

for (n in *data.frame*[,2]) {if(n-i>0) *data.frame*[i,2]=0 else i <- n}

I would be very appreciated if anybody can help.

Aucun commentaire:

Enregistrer un commentaire