I am trying to create a shapefile from a .csv file in R. I can successfully create a working shapefile with this code, but when I try to view the attribute table for it in arcMap 10.4, the table only contains columns for objectID, latitude, and longitude. I need the info in the other columns for symbolizing the data correctly.
Is there a way to specify which columns of the data to keep in the shapefile?
(I know how to make a data frame into a shapefile within arcMap, but I would like to automate this step in R if possible.)
library(maptools) library(rgdal) library(sp) #data site <- c("a","b","c","d") prop_c <- c(0.88,0.48,0.15,0.47) prop_b <- c(0.17,0.18,0.09,0.08) minus_c <- 1-prop_c minus_b <- 1-prop_b lat <- c(44.22,38.38,33.35,43.48) long <- c(-124.45, -123.70, -124.40, -124.05) MyData <- cbind.data.frame(site, prop_c, prop_b, minus_c, minus_b, lat, long) #convert data to shapefile WGScoor<- MyData #data to convert coordinates(WGScoor)=~long+lat #column names of the lat long cols proj4string(WGScoor)<- CRS("++proj=longlat +datum=WGS84") # set coordinate system to WGS WGScoor.df <- SpatialPointsDataFrame(WGScoor, data.frame(id=1:length(WGScoor))) LLcoor<-spTransform(WGScoor.df,CRS("+proj=longlat")) LLcoor.df=SpatialPointsDataFrame(LLcoor, data.frame(id=1:length(LLcoor))) writeOGR(LLcoor.df, dsn=getwd(),layer="MyShapefile",driver="ESRI Shapefile") #successfully creates shapefile that opens in arcGIS, #but shapefile does not include other columns in original data frame