我正在尝试使用 R 程序将 SpatialDataFrame (shapefile) 的两列合并为一列,但是在两列中都有空格,当它们与名称加 NA 一起时,但是我希望 NA 不会出现在我的新专栏。我使用了粘贴功能。像这样的东西:
This is the structure of my SpatialDataFrame:
ID city city2
1 1 saõ paulo <NA>
2 2 Rio de Janeiro <NA>
3 3 <NA> Belo Horizonte
4 4 <NA> Curitiba
obs。我的原始数据不是这个并且有更多的列
我用这个:
data$newCity <- paste(data$city, data$city2) # I don't want to show in my data Na
1.
ID city city2 newCity
1 saõ paulo <NA> saõ paulo NA
2 Rio de Janeiro <NA> Rio de Janeiro NA
3 <NA> Belo Horizonte NA Belo Horizonte
4 <NA> Curitiba NA Curitiba
事实上,这将是期望的结果:
ID city city2 newCity
1 saõ paulo <NA> saõ paulo
2 Rio de Janeiro <NA> Rio de Janeiro
3 <NA> Belo Horizonte Belo Horizonte
4 <NA> Curitiba Curitiba