[R] Iterate in a Spatial Polygon Dataframe in R?
Jon.SKOIEN at ec.europa.eu
Jon.SKOIEN at ec.europa.eu
Wed Oct 11 17:37:52 CEST 2017
Ashraf,
What do you want your function to do?
Currently you are overwriting p each time you go through your for-loop, and you finally return p = x[nrow(x), ]
It is similar to
y = 101:200
for (i in 1:100) {
x = y[i]
}
x
Best,
Jon
--
Jon Olav Skøien
European Commission
Joint Research Centre – JRC.E.1
Disaster Risk Management Unit
Building 26b 1/144 | Via E.Fermi 2749, I-21027 Ispra (VA) Italy, TP 267
Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.
________________________________________
From: R-help [r-help-bounces at r-project.org] on behalf of Ashraf Afana via R-help [r-help at r-project.org]
Sent: 11 October 2017 13:55
To: r-help at r-project.org
Subject: [R] Iterate in a Spatial Polygon Dataframe in R?
Hi all,
I'm trying to iterate in a SpatialPolygonDataFrame thatcontains 110 features. I tried to use the following code
iterate.spdf =function(x){ for (i in 1:nrow(x)){ p = x[i, ]} return(p)}
but with no success as it returns with aSpatialPolygonDataFrame that contains onlyone feature. The code seems to overwrite the polygons to end up with only onefeature.
Any suggestions?Ashraf, cheers
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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