Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test_data <- XXX
- # calculate the coefficient of variations in the local neighbour
- CV <- function(mean, sd){(sd/mean)*100}
- LocalCV = sapply(1:length(test_data),
- function(pt)
- {d = spDistsN1(test_data, test_data[pt,])
- return(CV(mean=mean(test_data[d < 5,]$Z),
- sd=sd(test_data[d < 5,]$Z)))})
- LocalCV[LocalCV > mean(LocalCV, na.rm = T)] <- NA
- Temprory.df <- na.omit(data.frame(test_data, LocalCV))
- coordinates(Temprory.df) <- c("coords.x1","coords.x2")
- # If the total number of CVs over 25% equals to
- # the total number of CVs within a search radius
- # then return TRUE or 1
- Num.CV = sapply(1:length(Temprory.df),
- function(pt) {d = spDistsN1(Temprory.df, Temprory.df[pt,])
- return(length(Temprory.df[d<5]$LocalCV[Temprory.df$LocalCV>25])
- ==length(Temprory.df[d<5]$LocalCV))})
- Error in `[.data.frame`(x@data, i, j, ..., drop = FALSE) :
- undefined columns selected
- Called from: `[.data.frame`(x@data, i, j, ..., drop = FALSE)
- coords.x1 coords.x2 Z
- 1 1803299 5786242 28.1757
- 2 1803297 5786242 30.6624
- 3 1803295 5786241 37.4547
- 4 1803293 5786241 39.6034
- 5 1803290 5786240 34.4702
- 6 1803288 5786239 38.8357
- 7 1803286 5786239 31.5278
- 8 1803284 5786239 20.4700
- 9 1803281 5786238 19.4517
- 10 1803279 5786238 24.8794
- 11 1803277 5786238 26.0178
- 12 1803274 5786238 30.4886
- 13 1803272 5786238 27.1075
- 14 1803270 5786238 27.6069
- 15 1803268 5786238 23.1940
- 16 1803268 5786238 10.2322
- 17 1803269 5786238 0.0000
- 18 1803270 5786238 0.0000
- 19 1803272 5786238 0.0000
- 20 1803274 5786238 0.0000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement