Question

i am completely new in R. I am trying to save a spatialdataframe and a normal data frame within the same object. when I am applying the code below, it saves the object as a R workspace, is it normal? i mean I wnated to obtain a .rda data instead. What i specifically want to do is to obtain an R data with those two objects. I want the spatialdataframe to keep its spatial charactheristics. Can someone help me?

##import a text table 
mcvfinal<-read.csv("dataCPWithAge.csv",header=TRUE,sep=",",dec=".") 

##reading the shapefile 
library(rgdal) polypc1 <- readOGR(".", "CP3poly_Matchingshp")   

##saving the two frames into the same object 
save(mcvfinal,polypc1,file="polypc.Rdata")
Was it helpful?

Solution

Try:

saveRDS(list(mcvfinal,polypc1),file="polypc.rds")

Load:

foo = readRDS("polypc.rds")

# mcvfinal is foo[[1]]
# polypc1 is foo[[2]]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top