R Under development (unstable) (2023-05-24 r84463 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > options("rgdal_show_exportToProj4_warnings"="none") > library(sp) The legacy packages maptools, rgdal, and rgeos, underpinning this package will retire shortly. Please refer to R-spatial evolution reports on https://r-spatial.org/r/2023/05/15/evolution4.html for details. This package is now running under evolution status 0 > data(meuse) > x = meuse > nm <- names(meuse) > # rename to non-default names: > nm[1] <- "xcoord" > nm[2] <- "ycoord" > names(x) <- nm > # change column order > x = x[ , c(3:14,2,1)] > coordinates(x) <- c("xcoord", "ycoord") # columns named xcoord and ycoord > coordinates(x)[1:10,] xcoord ycoord 1 181072 333611 2 181025 333558 3 181165 333537 4 181298 333484 5 181307 333330 6 181390 333260 7 181165 333370 8 181027 333363 9 181060 333231 10 181232 333168 > meuse[1:10,] x y cadmium copper lead zinc elev dist om ffreq soil lime 1 181072 333611 11.7 85 299 1022 7.909 0.00135803 13.6 1 1 1 2 181025 333558 8.6 81 277 1141 6.983 0.01222430 14.0 1 1 1 3 181165 333537 6.5 68 199 640 7.800 0.10302900 13.0 1 1 1 4 181298 333484 2.6 81 116 257 7.655 0.19009400 8.0 1 2 0 5 181307 333330 2.8 48 117 269 7.480 0.27709000 8.7 1 2 0 6 181390 333260 3.0 61 137 281 7.791 0.36406700 7.8 1 2 0 7 181165 333370 3.2 31 132 346 8.217 0.19009400 9.2 1 2 0 8 181027 333363 2.8 29 150 406 8.490 0.09215160 9.5 1 1 0 9 181060 333231 2.4 37 133 347 8.668 0.18461400 10.6 1 1 0 10 181232 333168 1.6 24 80 183 9.049 0.30970200 6.3 1 2 0 landuse dist.m 1 Ah 50 2 Ah 30 3 Ah 150 4 Ga 270 5 Ah 380 6 Ga 470 7 Ah 240 8 Ab 120 9 Ab 240 10 W 420 > class(x) [1] "SpatialPointsDataFrame" attr(,"package") [1] "sp" > sum = summary(x) > print(sum) Object of class SpatialPointsDataFrame Coordinates: min max xcoord 178605 181390 ycoord 329714 333611 Is projected: NA proj4string : [NA] Number of points: 155 Data attributes: cadmium copper lead zinc Min. : 0.200 Min. : 14.00 Min. : 37.0 Min. : 113.0 1st Qu.: 0.800 1st Qu.: 23.00 1st Qu.: 72.5 1st Qu.: 198.0 Median : 2.100 Median : 31.00 Median :123.0 Median : 326.0 Mean : 3.246 Mean : 40.32 Mean :153.4 Mean : 469.7 3rd Qu.: 3.850 3rd Qu.: 49.50 3rd Qu.:207.0 3rd Qu.: 674.5 Max. :18.100 Max. :128.00 Max. :654.0 Max. :1839.0 elev dist om ffreq soil lime Min. : 5.180 Min. :0.00000 Min. : 1.000 1:84 1:97 0:111 1st Qu.: 7.546 1st Qu.:0.07569 1st Qu.: 5.300 2:48 2:46 1: 44 Median : 8.180 Median :0.21184 Median : 6.900 3:23 3:12 Mean : 8.165 Mean :0.24002 Mean : 7.478 3rd Qu.: 8.955 3rd Qu.:0.36407 3rd Qu.: 9.000 Max. :10.520 Max. :0.88039 Max. :17.000 NA's :2 landuse dist.m W :50 Min. : 10.0 Ah :39 1st Qu.: 80.0 Am :22 Median : 270.0 Fw :10 Mean : 290.3 Ab : 8 3rd Qu.: 450.0 (Other):25 Max. :1000.0 NA's : 1 > coordinates(x) xcoord ycoord 1 181072 333611 2 181025 333558 3 181165 333537 4 181298 333484 5 181307 333330 6 181390 333260 7 181165 333370 8 181027 333363 9 181060 333231 10 181232 333168 11 181191 333115 12 181032 333031 13 180874 333339 14 180969 333252 15 181011 333161 16 180830 333246 17 180763 333104 18 180694 332972 19 180625 332847 20 180555 332707 21 180642 332708 22 180704 332717 23 180704 332664 24 181153 332925 25 181147 332823 26 181167 332778 27 181008 332777 28 180973 332687 29 180916 332753 30 181352 332946 31 181133 332570 32 180878 332489 33 180829 332450 34 180954 332399 35 180956 332318 37 180710 332330 38 180632 332445 39 180530 332538 40 180478 332578 41 180383 332476 42 180494 332330 43 180561 332193 44 180451 332175 45 180410 332031 46 180355 332299 47 180292 332157 48 180283 332014 49 180282 331861 50 180270 331707 51 180199 331591 52 180135 331552 53 180237 332351 54 180103 332297 55 179973 332255 56 179826 332217 57 179687 332161 58 179792 332035 59 179902 332113 60 180100 332213 61 179604 332059 62 179526 331936 63 179495 331770 64 179489 331633 65 179414 331494 66 179334 331366 67 179255 331264 69 179470 331125 75 179692 330933 76 179852 330801 79 179140 330955 80 179128 330867 81 179065 330864 82 179007 330727 83 179110 330758 84 179032 330645 85 179095 330636 86 179058 330510 87 178810 330666 88 178912 330779 89 178981 330924 90 179076 331005 123 180151 330353 160 179211 331175 163 181118 333214 70 179474 331304 71 179559 331423 91 179022 330873 92 178953 330742 93 178875 330516 94 178803 330349 95 179029 330394 96 178605 330406 97 178701 330557 98 179547 330245 99 179301 330179 100 179405 330567 101 179462 330766 102 179293 330797 103 179180 330710 104 179206 330398 105 179618 330458 106 179782 330540 108 179980 330773 109 180067 331185 110 180162 331387 111 180451 331473 112 180328 331158 113 180276 330963 114 180114 330803 115 179881 330912 116 179774 330921 117 179657 331150 118 179731 331245 119 179717 331441 120 179446 331422 121 179524 331565 122 179644 331730 124 180321 330366 125 180162 331837 126 180029 331720 127 179797 331919 128 179642 331955 129 179849 332142 130 180265 332297 131 180107 332101 132 180462 331947 133 180478 331822 134 180347 331700 135 180862 333116 136 180700 332882 161 180201 331160 162 180173 331923 137 180923 332874 138 180467 331694 140 179917 331325 141 179822 331242 142 179991 331069 143 179120 330578 144 179034 330561 145 179085 330433 146 179236 330046 147 179456 330072 148 179550 329940 149 179445 329807 150 179337 329870 151 179245 329714 152 179024 329733 153 178786 329822 154 179135 329890 155 179030 330082 156 179184 330182 157 179085 330292 158 178875 330311 159 179466 330381 164 180627 330190 > > x <- as.data.frame(x) > class(x) [1] "data.frame" > > x[1:10, c("xcoord", "ycoord")] xcoord ycoord 1 181072 333611 2 181025 333558 3 181165 333537 4 181298 333484 5 181307 333330 6 181390 333260 7 181165 333370 8 181027 333363 9 181060 333231 10 181232 333168 > > x = meuse[1:4,] > coordinates(x) = c(1,2) > # row 1,2; cols 1:10 > x[1:2,1:10] coordinates cadmium copper lead zinc elev dist om ffreq soil 1 (181072, 333611) 11.7 85 299 1022 7.909 0.00135803 13.6 1 1 2 (181025, 333558) 8.6 81 277 1141 6.983 0.01222430 14.0 1 1 lime 1 1 2 1 > # row 2, coord+col 9,10 > x[2,9:10] coordinates soil lime 2 (181025, 333558) 1 1 > # coordinates, col 9+10 > x[,9:10] coordinates soil lime 1 (181072, 333611) 1 1 2 (181025, 333558) 1 1 3 (181165, 333537) 1 1 4 (181298, 333484) 2 0 > # coordinates + col 9: > x[,9] coordinates soil 1 (181072, 333611) 1 2 (181025, 333558) 1 3 (181165, 333537) 1 4 (181298, 333484) 2 > # coordinates + zinc column: > x["zinc"] coordinates zinc 1 (181072, 333611) 1022 2 (181025, 333558) 1141 3 (181165, 333537) 640 4 (181298, 333484) 257 > # second row, coordinates + zinc > x[2,"zinc"] coordinates zinc 2 (181025, 333558) 1141 > # select; re-orders: > x[c("zinc","copper")] coordinates zinc copper 1 (181072, 333611) 1022 85 2 (181025, 333558) 1141 81 3 (181165, 333537) 640 68 4 (181298, 333484) 257 81 > # back as data.frame > as.data.frame(x)[1:3, c("zinc","copper","x", "y")] zinc copper x y 1 1022 85 181072 333611 2 1141 81 181025 333558 3 640 68 181165 333537 > > proc.time() user system elapsed 0.35 0.10 0.45