小编Ye *_* Xu的帖子

在R中如何将经度和纬度转换为可以在ggplot2或ggmap中使用的格式

我有一个原始的经度/纬度数据,其格式无法由R map处理.所以我想知道是否有一些R函数或算法来帮助我将这些原始数据转换为可读格式.(也许是UTM)这是我的原始数据:

纬度: "32-14-23 N""31-04-27 N""33-45-28 N"

经度: "121-22-38 W""119-30-05 W""122-47-52 W"

我希望将格式转换为(下面的示例是模拟数据):

经度: -2.748

纬度: 53.39

geography r coordinates ggplot2 ggmap

4
推荐指数
1
解决办法
4472
查看次数

在R中,如何解释大于/小于的switch语句

在R语言中,我想使用switch语句来替换nest if else语句.我想为新列分配值,我的想法是:

## Create a function to seperate the case

Range <- function(x)
    if (CityData_Group_Copy$BadDebtNum[x] < 26)  
              { CityData_Group_Copy$BadDebtRange[x] <- "1~25"}

    else if(CityData_Group_Copy$BadDebtNum[x] > 25 && CityData_Group_Copy$BadDebtNum[x] < 51)  
              {CityData_Group_Copy$BadDebtRange[x] <- "26~50"}

    else if(CityData_Group_Copy$BadDebtNum[x] > 51 && CityData_Group_Copy$BadDebtNum[x] < 76)   
              {CityData_Group_Copy$BadDebtRange[x] <- "51~75"}

    else if(CityData_Group_Copy$BadDebtNum[x] > 75 && CityData_Group_Copy$BadDebtNum[x] < 101)  
              {CityData_Group_Copy$BadDebtRange[x] <- "76~100"}

    else if(CityData_Group_Copy$BadDebtNum[x] > 100)
              { CityData_Group_Copy$BadDebtRange[x] <- "100+"}


## Assign the result to the new column "CityData_Group_Copy$BadDebtRange" 

for(i in 1: nrow(CityData_Group_Copy) ){
  Range(i)
}
Run Code Online (Sandbox Code Playgroud)

我也试过这个解决方案: …

r switch-statement

1
推荐指数
1
解决办法
3817
查看次数

标签 统计

r ×2

coordinates ×1

geography ×1

ggmap ×1

ggplot2 ×1

switch-statement ×1