Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. test_data <- XXX
  2.  
  3. # calculate the coefficient of variations in the local neighbour
  4.  
  5. CV <- function(mean, sd){(sd/mean)*100}
  6.  
  7. LocalCV = sapply(1:length(test_data),
  8. function(pt)
  9. {d = spDistsN1(test_data, test_data[pt,])
  10. return(CV(mean=mean(test_data[d < 5,]$Z),
  11. sd=sd(test_data[d < 5,]$Z)))})
  12.  
  13. LocalCV[LocalCV > mean(LocalCV, na.rm = T)] <- NA
  14.  
  15. Temprory.df <- na.omit(data.frame(test_data, LocalCV))
  16.  
  17. coordinates(Temprory.df) <- c("coords.x1","coords.x2")
  18.  
  19. # If the total number of CVs over 25% equals to
  20. # the total number of CVs within a search radius
  21. # then return TRUE or 1
  22.  
  23. Num.CV = sapply(1:length(Temprory.df),
  24. function(pt) {d = spDistsN1(Temprory.df, Temprory.df[pt,])
  25. return(length(Temprory.df[d<5]$LocalCV[Temprory.df$LocalCV>25])
  26. ==length(Temprory.df[d<5]$LocalCV))})
  27.  
  28. Error in `[.data.frame`(x@data, i, j, ..., drop = FALSE) :
  29. undefined columns selected
  30. Called from: `[.data.frame`(x@data, i, j, ..., drop = FALSE)
  31.  
  32. coords.x1 coords.x2 Z
  33. 1 1803299 5786242 28.1757
  34. 2 1803297 5786242 30.6624
  35. 3 1803295 5786241 37.4547
  36. 4 1803293 5786241 39.6034
  37. 5 1803290 5786240 34.4702
  38. 6 1803288 5786239 38.8357
  39. 7 1803286 5786239 31.5278
  40. 8 1803284 5786239 20.4700
  41. 9 1803281 5786238 19.4517
  42. 10 1803279 5786238 24.8794
  43. 11 1803277 5786238 26.0178
  44. 12 1803274 5786238 30.4886
  45. 13 1803272 5786238 27.1075
  46. 14 1803270 5786238 27.6069
  47. 15 1803268 5786238 23.1940
  48. 16 1803268 5786238 10.2322
  49. 17 1803269 5786238 0.0000
  50. 18 1803270 5786238 0.0000
  51. 19 1803272 5786238 0.0000
  52. 20 1803274 5786238 0.0000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement