我有一张经度和纬度的进口桌子,想要从中创建一个空间网格。 坐标采用以下格式:
[1] 6.955 6.937 6.956 6.923
所以对我来说看起来很数字。但是尝试创建网格时会出现此错误:
.local(obj,...)出错:
派生坐标
无法从非数字矩阵
当我尝试使用as.numeric更改格式时,我得到以下结果:
[1] 10 9 6 8
如何在不更改值的情况下转换数字格式的坐标?
longitude = structure(c(9L, 7L, 10L, 3L, 8L, 4L, 6L, 2L, 11L, 1L, 5L, 9L,
7L, 10L, 3L, 8L, 4L, 6L, 2L, 11L, 1L, 5L), .Label = c("6.920",
"6.922", "6.923", "6.924", "6.926", "6.936", "6.937", "6.939",
"6.955", "6.956", "6.958"), class = "factor")
latitude = structure(c(10L, 9L, 6L, 8L, 1L, 5L, 3L, 2L, 7L, 8L, 4L, 10L,
9L, 6L, 8L, 1L, 5L, 3L, 2L, 7L, 8L, 4L), .Label = c("50.911",
"50.918", "50.920", "50.929", "50.930", "50.931", "50.934", "50.950",
"50.965", "50.969"), class = "factor")
原始表luftdaten.set
包含纬度,经度和颗粒物质值。我试图创建一个网格:
coordinates(luftdaten.set) <- ~ latitude + longitude
我还尝试创建一个只包含坐标的数据框,并尝试从中导出一个网格:
luftdaten.grid <- data.frame(latitude, longitude)
luftdaten.grid <- data.frame(latitude, longitude)
两者都抛出所描述的错误。
coordinates
位于SpatialTools&#39; sp&#39;封装
答案 0 :(得分:1)
这样可行:
longitude <- as.numeric(as.character(longitude))
latitude <- as.numeric(as.character(latitude))
luftdaten.grid <- data.frame(latitude, longitude)
attach(luftdaten.grid)
coordinates(luftdaten.grid) <- ~ latitude + longitude
答案 1 :(得分:0)
假设您正在尝试获取矩阵,其中每一行都是纬度/长度对:
as.matrix(cbind(as.numeric(as.character(latitude)),
as.numeric(as.character(longitude))))
[,1] [,2]
[1,] 50.969 6.955
[2,] 50.965 6.937
[3,] 50.931 6.956
[4,] 50.950 6.923
[5,] 50.911 6.939
[6,] 50.930 6.924
[7,] 50.920 6.936
[8,] 50.918 6.922
[9,] 50.934 6.958
[10,] 50.950 6.920
[11,] 50.929 6.926
[12,] 50.969 6.955
[13,] 50.965 6.937
[14,] 50.931 6.956
[15,] 50.950 6.923
[16,] 50.911 6.939
[17,] 50.930 6.924
[18,] 50.920 6.936
[19,] 50.918 6.922
[20,] 50.934 6.958
[21,] 50.950 6.920
[22,] 50.929 6.926