-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps_data_code.R
More file actions
34 lines (30 loc) · 830 Bytes
/
maps_data_code.R
File metadata and controls
34 lines (30 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
getwd()
#setwd(" ") (if any)
if(!require(readxl))
install.packages("readxl")
library(readxl)
mydata <- read_xlsx("Long_Lattitufde.xlsx")
names(mydata)
str(mydata)
class(mydata)
test <- as.data.frame(mydata)
if(!require(sp))
install.packages("sp")
if(!require(maps))
install.packages("maps")
if(!require(maptools))
install.packages("maptools")
library(maps)
library(sp)
library(maptools)
post_rem_dt <- na.omit(mydata)
req_dt <- as.data.frame(post_rem_dt)
result <- data.frame(nrow = 10,ncol = 3)
res <- lapply(with(req_dt, paste(lat, lon, sep = ",")), geocode, output = "more")
final <- character()
for(i in 1:nrow(req_dt)){
final[i] <- as.character(res[[i]]$administrative_area_level_1)
}
final <- as.data.frame(final)
final_result <- cbind(req_dt,final)
write.csv(final_result,file = "latlong2states_updated.csv")