Skip to main content

Command Palette

Search for a command to run...

5- Exporting data from R programming

Updated
•1 min read•View as Markdown
A
I am an Assistant Professor of Remote Sensing in the Department of Geography at the Soran University. My research interests include remote sensing, GIS, climate and environment. More specifically, I am interested in applying geospatial big data, programming and cloud computing (e.i. Google Earth Engine) to study environmental change, especially land use land cover and climate monitoring. More information about my research and teaching can be found at https://www.linkedin.com/in/azad-rasul-1860abb1/.

Create data:

data <- c(1977, 1979, 2013, 2014,'', 2015)

Save data as comma-separated CSV format:

write.csv(data, 'created_data.csv')

Save as semicolon-separated CSV file:

write.csv2(data, file='data_semicolon.csv')

Save data as text file:

write.table(data, file= 'data.txt', sep = '\t', row.names=T) # \t is tab

Save as RData:

If we have objects a, b, c, d, and e, we can save them as RData and reload them in a new session:

a<- c(5)
b<- c(-1)
c<- c(15)
d<- c(55)
e<- c('NA')
save(a, b, c, d, e, file='test.RData') # Rdata is used to save multiple R objects
load('C:\\Users\\Azad\\Documents\\test.RData')

Save an object to RDS file:

saveRDS(data, 'firstData.rds')
# Restore it
rds_data <- readRDS("firstData.rds") # Rds is used to save a single R object

Save workspace:

The workspace is your current R working environment and includes any user-defined objects (vectors, matrices, data frames, lists, functions).

save.image(file='workspace_2021.RData')
load('workspace_2021.RData')

Compressing and saving files:

write.csv(data, file = bzfile('data_ziped.csv.bz2'))

If you enjoy the content, please consider subscribing to my YouTube channel for future updates.

To access video tutorials and receive a certificate, enroll in my Udemy course.

V

https://vid-mate.mobi/ https://vid-mate.mobi/download/ https://vid-mate.mobi/android/

More from this blog

SmartRS – Remote Sensing, GIS & Data Science Tutorials

127 posts

Practical, step-by-step tutorials on remote sensing, GIS, climate data and data science with R, Python and JavaScript: satellite image analysis, spatial data processing, and data visualization. Written by Dr. Azad Rasul, Assistant Professor of Remote Sensing and GIS.