Show Menu
Cheatography

Data import/export in R Cheat Sheet by

Data import/export in R

Abstract

In the process of learning progra­mming, utilizing well-o­rga­nized cheats­heets is a valuable technique. This "Data Import­/Export in R" cheatsheet offers a quick reference guide for effici­ently handling different file types in R. It covers importing and exporting CSV, TXT, XLS, XLSX, TSV, RDS, RDA, JSON, XML, images (JPG/P­NG/­TIF­F/BMP), audio (MP3), video (MP4), HDF5, and netCDF files. Each slide provides concise R code for reading and writing specific file formats. This cheatsheet aims to empower learners with the necessary knowledge to manipulate and analyze diverse datasets effect­ively using R's data import­/export capabi­lities.

Introd­uction

R is a powerful progra­mming language for data analysis.
Efficient data import­/export is crucial for data manipu­lation and analysis.
This cheatsheet provides quick reference on readin­g/w­riting various file types in R.

Conclusion

Proper data import­/export enhances R's data analysis capabi­lities.
Use this cheatsheet as a handy reference guide in your R progra­mming journey.

Thank You

Thank you for using this "Data Import­/Export in R" cheats­heet.
For more resources, visit my websit­e[h­ttp­s:/­/vc­cv.cc].
 

CSV

Import
Export
read.c­sv(­file, 
header = TRUE,
sep = " ",
comment.char = "­",
...)
write.c­sv(x, 
file = "­",
append = FALSE,
sep = " ",
row.names = TRUE,
...)
File:
the name of the file which the data are to be read from.
X:
the object to be written, preferably a matrix or data frame.

TXT

Import
Export
read.t­abl­e(file, 
header = TRUE,
sep = " ",
comment.char = "­",
...)
write.t­ab­le(x, 
file = "­",
append = FALSE,
sep = " ",
row.names = TRUE,
...)
File:
the name of the file which the data are to be read from.
X:
the object to be written, preferably a matrix or data frame.
Code: read.t­abl­e(file, header­=TRUE)
Code: write.t­ab­le(x, export.txt)

Video/­HDF­5/n­etCDF

Video
HDF5
Read Video:
videop­lay­R::­rea­dMP4()
Read HDF5:
hdf5r:­:h5­read()
Write Video:
videop­lay­R::­wri­teMP4()
Write HDF5:
hdf5r:­:h5­write()
netCDF
Read netCDF:
ncdf4:­:nc­_open()
Write netCDF:
ncdf4:­:nc­var­_put()
 

TSV/RD­S/RDA

TSV
RDS
RDA
Read TSV:
read.t­able()
Read RDS:
readRDS()
Read RDA:
attach()
Write TSV:
write.t­able()
Write RDS:
saveRDS()

JSON/XML

JSON
XML
Read JSON:
jsonli­te:­:fr­omJ­SON()
Read XML:
XML::x­mlT­ree­Parse()
Write JSON:
jsonli­te:­:to­JSON()
Write XML:
XML::s­ave­XML()

XLS/XLSX

XLS
XLSX
Read XLS:
readxl­::r­ead­_ex­cel()
Read XLSX:
readxl­::r­ead­_xlsx()
Write XLS:
writex­l::­wri­te_­xlsx()
Write XLSX:
writex­l::­wri­te_­xlsx()

Image/­Audio

Image
Audio
Read Images:
jpeg::­rea­dJPEG()
,
png::r­ead­PNG()
,
tiff::­rea­dTIFF()
,
bmp::r­ead­BMP()
Read Audio:
tuneR:­:re­adMP3()
Write Images:
jpeg::­wri­teJ­PEG()
,
png::w­rit­ePNG()
,
tiff::­wri­teT­IFF()
,
bmp::w­rit­eBMP()
Write Audio:
tuneR:­:wr­ite­MP3()
           
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.