我正在使用下面的代码构建一组坐标以在GGMAP上绘制。
coords <- rbind(as.matrix(rte[,7:8]),as.matrix(rte[nrow(rte),9:10])) %>%
as.data.frame()
这将生成以下数据。我遇到的问题是终点(最后一点/行)。
由于存在重复值(9.3),我收到错误 - 我需要重命名前一个值的+0.1,即9.4。
structure(list(startLon = c(-2.8812933, -2.8836377, -2.8846959,
-2.883528, -2.8867415, -2.8878325, -2.8880098, -2.8895748, -2.8935501,
-2.8971835, -2.8987187, -2.8989829, -2.8986408, -2.8989038, -2.897305,
-2.8939165, -2.8932886, -2.8932332, -2.8932886, -2.891303, -2.8904392,
-2.8896841, -2.8900902, -2.8896841, -2.8916631, -2.8908963, -2.889908,
-2.889908, -2.8897949, -2.8877892, -2.8879832), startLat = c(53.1935042,
53.1934807, 53.1962441, 53.1968895, 53.1943495, 53.1938296, 53.1936907,
53.1943944, 53.1942666, 53.1939625, 53.1931411, 53.1930795, 53.1928816,
53.1926769, 53.1893671, 53.1898796, 53.1899857, 53.1899088, 53.1899857,
53.1903599, 53.1905145, 53.1906626, 53.1912708, 53.1906626, 53.1902482,
53.1884563, 53.1868239, 53.1868239, 53.1866933, 53.1877751, 53.1884169
)), .Names = c("startLon", "startLat"), row.names = c("1.1",
"1.2", "1.3", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7",
"3.1", "3.2", "3.3", "3.4", "3.5", "4.1", "4.2", "5.1", "5.2",
"5.3", "6.1", "6.2", "7.1", "7.2", "7.3", "7.4", "8", "9.1",
"9.2", "9.3", "9.3"), class = "data.frame")
这样做的最佳方式是什么?
答案 0 :(得分:3)
这是一个通用的解决方案:
mx1 <- matrix(1:10, 5, dimnames=list(c("1", "1", "1", "2", "2"), NULL))
mx1 %>% `row.names<-`(make.unique(row.names(.))) %>% as.data.frame
产地:
V1 V2
1 1 6
1.1 2 7
1.2 3 8
2 4 9
2.1 5 10