How to import SAS, SPSS, Excel, CSV, XML, JSON, Stata, minitab data into R

0
2775
Source - R Project website
Source - R Project website

R is the open source analytics software which everyone loves to use these days. Advantage of R over python is mostly easiness to use and adapt. Hence, we are starting the series of articles/ tutorials on R. This is first tutorial on R which talks about importing different types of datasets into R in different ways.

Importing CSV data into R using R console –

First, check for the default path of R using following command –

getwd()

Now, set your own path of R for data default data libraries in R –

setwd(“C:/Users/cooldude/Documents/Rtutorials/New folder”)

Once you set up this path, put your CSV dataset into that path you have set in above code. Then, write following command in R console to import the CSV dataset.

Importeddata <- read.csv(“forimport_data.csv”, header=T)

In above R command, ‘header = T’ signifies that first row will be with headers or titles of each column of CSV file.

Importing excel data into R using R console –

Here is the code to connect to Excel workbook and load excel files into R

library(XLConnect)

Importeddata <- readWorksheetFromFile(“Input filename and the extension in this bracket”, sheet = 1)

Importing JSON files into R using R console –

library(rjson)

Importeddata <- fromJSON(file = “Input filename here.json>” )

Importing XML data into R using R console –

library(XML)

importeddata <- xmlTreeParse(“<input URL of XML data here>”)

Importing SPSS and STATA files in R using R console-

library(foreign)

Importeddata <- read.spss(“filename.sav”) //for SPSS//

Importeddata <- read.dta(“<Path of the file>”) //for STATA//

Importing SAS files in R using R console –

library(sas7bdat)

ImportedData <- read.sas7bdat(“filename.sas7bdat”)

Importing MiniTab files into R using R console –

library(foreign)

ImportedData <- read.mtp(“filename.mtp”)

Importing any data into R using R studio –

Here is how you can import dataset of any type in R studio –

r-import

This is one of the reasons many people prefer R studio because it is extremely easy to use and does not require much programming.

 

NO COMMENTS

LEAVE A REPLY