Debian Codegraph @

tests/sp1.R

raw
1 options("rgdal_show_exportToProj4_warnings"="none")
2 source("utils/print.R")
3
4 library(sp)
5 data(meuse)
6 x = meuse
7 nm <- names(meuse)
8 # rename to non-default names:
9 nm[1] <- "xcoord"
10 nm[2] <- "ycoord"
11 names(x) <- nm
12 # change column order
13 x = x[ , c(3:14,2,1)]
14 coordinates(x) <- c("xcoord", "ycoord") # columns named xcoord and ycoord
15 coordinates(x)[1:10,]
16 meuse[1:10,]
17 class(x)
18 sum = summary(x)
19 print(sum)
20 coordinates(x)
21
22 x <- as.data.frame(x)
23 class(x)
24
25 x[1:10, c("xcoord", "ycoord")]
26
27 x = meuse[1:4,]
28 coordinates(x) = c(1,2)
29 # row 1,2; cols 1:10
30 x[1:2,1:10]
31 # row 2, coord+col 9,10
32 x[2,9:10]
33 # coordinates, col 9+10
34 x[,9:10]
35 # coordinates + col 9:
36 x[,9]
37 # coordinates + zinc column:
38 x["zinc"]
39 # second row, coordinates + zinc
40 x[2,"zinc"]
41 # select; re-orders:
42 x[c("zinc","copper")]
43 # back as data.frame
44 as.data.frame(x)[1:3, c("zinc","copper","x", "y")]