SlideShare a Scribd company logo
Presented by: 1) Bhavesh Sarvaiya(115347)
2) Naresh Sarvaiya(115340)
R Data Interfaces
Topics
CSV Files
Excel Files
Database
XML Files
JSON Files
Web Data
Get Facebook data
CSV Files
How to Read CSV Files in R ?
 The csv file is a text file in which the values in the
columns are separated by a comma.
 Each cell inside such data file is separated by a
special character, which usually is a comma, although
other characters can be used as well.
 Example: student info
"No", "Name", "age"
1,Bhavesh,22
2,Ramesh,20
3,Karmraj,22
• Copy it and paste into notepad and save as mydata.csv
Continue…
read.csv()
• read.csv(file, header = TRUE, sep = ",", quote = """, dec = ".",
comment.char = “-", ...)
• The read.csv() function has a few important arguments:
• file, the name of a file, or a connection
• header, logical indicating if the file has a line
• sep, a string indicating how the columns are separated
• comment.char, a character string indicating the comment
character. This defalts to "#". If there
are no commented lines in your file, it’s worth setting this to
be the empty string "".
• skip, the number of lines to skip from the beginning
• mydata = read.csv("mydata.csv")
• print(mydata)
No Name age
1 Bhavesh 22
2 Ramesh 20
3 Karmraj 22
Continue…
• print(is.data.frame(data)) = TRUE
• print(ncol(data)) = 3
• print(nrow(data)) = 3
• Get the maximum age
• age<- max(mydata$age)
• print(age)
write.csv()
• write.csv(x, file = "", append = FALSE, quote = TRUE, sep = ",",
eol = "n", na = "NA", dec = ".", row.names = TRUE, col.names =
TRUE)
• write.csv(mydata,file = "t.csv ")
• write.csv(mydata,file = "t.csv",row.names = F)
Excel Files
How to Read Excel Files in R ?
 Microsoft Excel is the most widely used spreadsheet program which
stores data in the .xls or .xlsx format.
 install.packages("xlsx")
 Load the library into R workspace
library("xlsx")
 Example: employee info
id name salary start_date dept
1 Rick 623.3 1/1/2012 IT
2 Dan 515.2 9/23/2013 Operations
3 Michelle 611 11/15/2014 IT
4 Ryan 729 5/11/2014 HR
5 Gary 843.25 3/27/2015 Finance
6 Nina 578 5/21/2013 IT
7 Simon 632.8 7/30/2013 Operations
8 Guru 722.5 6/17/2014 Finance
Copy it and open microsoft excel and save as named input.xlsx
Continue…
read.xlsx()
• read.xlsx(file, sheetIndex, sheetName = NULL, rowIndex = NULL,
startRow = NULL, endRow=NULL, colIndex=NULL, as.data.frame = TRUE,
header=TRUE, keepFormulas = FALSE)
• data <- read.xlsx("input.xlsx", sheetIndex = 1)
• print(data)
write.xlsx()
• write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
eol = "n", na = "NA", dec = ".", row.names = TRUE, col.names =
TRUE, qmethod = c("escape", "double"), fileEncoding = "")
• write.xlsx(data,file = "new.xlsx",sheetName = "s1")
Database
 The data is Relational database systems are stored in a
normalized format.
 So, to carry out statistical computing we will need very
advanced and complex Sql queries.
 But R can connect easily to many relational databases like
MySql, Oracle, Sql server etc. and fetch records from them
as a data frame.
 Once the data is available in the R environment, it
becomes a normal R data set and can be manipulated or
analyzed using all the powerful packages and functions.
Continue..
RMySQL Package
install.packages("RMySQL")
• Opening and closing connections
• mysqlconnection<-dbConnect(MySQL(),user="root",password
= "mysql", dbname = "sakila", host = "localhost")
• on.exit(dbDisconnect(mysqlconnection))
• Processing query results
• List the tables available in this database.
dbListTables(mysqlconnection)
Continue..
• Get record from table
• rs <- dbSendQuery(con, "select * from city limit 10;")
• data <- fetch(rs, n=10)
• Creating Tables in MySql
• dbWriteTable(mysqlconnection,“mtcars",iris[1:10,])
• Inserting Data into the Tables
• dbSendQuery(mysqlconnection, "insert into
mtcars(row_names, mpg, cyl, disp, hp, drat, wt, qsec, vs,
am, gear, carb) values('New Mazda RX4 Wag', 21, 6, 168.5,
110, 3.9, 2.875, 17.02, 0, 1, 4, 4)" )
Continue..
• Updating Rows in the Tables
• dbSendQuery(mysqlconnection, "update mtcars set
disp = 168.5 where hp = 110")
• Dropping Tables in MySql
• dbSendQuery(mysqlconnection, 'drop table if exists
mtcars')
XML Files
• XML is a file format which shares both the file format
and the data on the World Wide Web, intranets, and
elsewhere using standard ASCII text.
• You can read a xml file in R using the "XML" package.
• install.packages("XML")
 Input Data
• Click below link to open xml file
• Parts.xml
• Then read the file from r
Continue…
• Reading XML File
• xmlParse()
• Give the input file name to the function.
• result <- xmlParse(file = "parts.xml")
• Exract the root node from the xml file.
• rootnode <- xmlRoot(result)
• Find number of nodes in the root.
rootsize<-xmlSize(rootnode)
• Get the first element of the first node.
print(rootnode[[1]][[1]])
Continue…
• XML to Data Frame
• xmlToDataFrame()
• Convert the input xml file to a data frame.
• xmldataframe <- xmlToDataFrame(“parts.xml")
• print(xmldataframe)
JSON Files
• JSON file stores data as text in human-readable format.
• Json stands for JavaScript Object Notation.
• R can read JSON files using the rjson package.
• You can read a Json file in R using the "rjson" package.
• install.packages(“rjson")
Input Data
Copy following data and paste into notepad and save as
rjsonfile.json
{
"ID":["1","2","3","4","5","6","7","8" ], "Name":["bhavesh",
"kiran", "mital", "yograj", "ramesh", "gita", "manan", "sital" ],
"Salary":["623.3","515.2","611","729","843.25","578","632.8","722
.5" ],
"StartDate":[1/1/2012","9/23/2013","11/15/2014","5/11/2014","3/27
/2015","5/21/2013", "7/30/2013","6/17/2014"],
"Dept":["IT","Operations","IT","HR","Finance","IT","Operations","
Finance"]
}
Continue….
• Reading JSON File
• FromJSON()
• Give the input file name to the function.
• result <- fromJSON(file = "rjsonfile.xml")
• Print(result)
• Convert JSON to a Data Frame
• We can convert the extracted data above to a R data
frame for further analysis the as.data.frame() function.
• json_data_frame <- as.data.frame(result)
• print(json_data_frame)
Web Data
• Many websites provide data for consumption by its users.
• For example the World Health Organization(WHO) provides
reports on health and medical information in the form of
CSV, txt and XML files.
• Using R programs, we can programmatically extract
specific data from such websites.
• Some packages in R which are used to scrap data form the
web are − "RCurl",XML", and "stringr".
• Install R Packages
• install.packages("RCurl")
• install.packages("XML")
• install.packages("stringr")
• install.packages("plyr")
Continue…
• Input Data
• We will use the function getHTMLLinks() to gather the
URLs of the files.
• Then we will use the function download.file() to save
the files to the local system.
• url <- http://gujaratvidyapith.org/
• Gather the html links present in the webpage.
• links <- getHTMLLinks(url)
• Identify only the links which point to the JCMB 2017 files.
• filenames <- links[str_detect(links, "JCMB_2017")]
• Store the file names as a list.
• filenames_list <- as.list(filenames)
Continue…
• Input Data
• Create a function to download the files by passing
the URL and filename list.
downloadcsv <- function (url,filename)
{
filedetails <- str_c(url,filename)
download.file(filedetails,filename)
}
• Now apply downloadcsv function and save the files
into the current R working directory.
downloadcsv(url,filename)
Get Facebook data
• Step 1 : Facebook Developer Registration
• Go to https://developers.facebook.com and register yourself
by clicking on Get Started button
• Step 2 : Add a new App
• click on My Apps button. Then select Add a New App from the
drop down.
• Step 3 : Get App ID and App Secret
• Step 4 : OAuth Settings
1. On the left hand side menu, click on Add Product Button
2. Click on Facebook Login link
3. Under Settings, make sure YES is selected in Client OAuth Login
4. Type http://localhost:1410/ in Valid OAuth redirect URIs box
5. Click on Save Changes button
Continue…
• Install required packages
• install.packages("Rfacebook")
• install.packages("RCurl")
• Paste your app id and app secret below
• fb_oauth <- fbOAuth(app_id="183xxxxxxxx3748",
app_secret="7bfxxxxxxxxcf0",extended_permissions =
TRUE)
• Check your profile account information
• me <- getUsers("me",token=fb_oauth,
private_info=TRUE)
• me$name
Continue…
• List of all the pages you have liked
• likes = getLikes(user="me", token = tt)
• sample(likes$names, 10)
• Extract list of posts from a Facebook page
• page <- getPage(page="bbcnews", token=tt, n=200)
• Which of these posts got maximum likes?
• summary = page[which.max(page$likes_count),]
• summary$message
Reference
• https://www.tutorialspoint.com
• http://www.listendata.com/2017/03/facebook-data-mining-
using-r.html
THANK YOU

More Related Content

What's hot

1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
koolkampus
 
Database Management System ppt
Database Management System pptDatabase Management System ppt
Database Management System ppt
OECLIB Odisha Electronics Control Library
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Data file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing filesData file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing files
keeeerty
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
NILESH UCHCHASARE
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
Jafar Nesargi
 
DBMS _Relational model
DBMS _Relational modelDBMS _Relational model
DBMS _Relational model
Azizul Mamun
 
MODULE 1_Introduction to Data analytics and life cycle..pptx
MODULE 1_Introduction to Data analytics and life cycle..pptxMODULE 1_Introduction to Data analytics and life cycle..pptx
MODULE 1_Introduction to Data analytics and life cycle..pptx
nikshaikh786
 
Ch 3 E R Model
Ch 3  E R  ModelCh 3  E R  Model
Ch 3 E R Model
guest8fdbdd
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
Visakh V
 
Client Server Computing : unit 1
Client Server Computing : unit 1Client Server Computing : unit 1
Client Server Computing : unit 1
THIRUNEELAKANDAN ARCHUNAN
 
Web mining (structure mining)
Web mining (structure mining)Web mining (structure mining)
Web mining (structure mining)
Amir Fahmideh
 
Edi layer
Edi layerEdi layer
Edi layer
Sheetal Verma
 
System and its types
System and its typesSystem and its types
System and its types
nidhipandey79
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
Jargalsaikhan Alyeksandr
 
Inter Organizational e-commerce
Inter Organizational e-commerceInter Organizational e-commerce
Inter Organizational e-commerce
RajaKrishnan M
 
Kskv kutch university DBMS unit 1 basic concepts, data,information,database,...
Kskv kutch university DBMS unit 1  basic concepts, data,information,database,...Kskv kutch university DBMS unit 1  basic concepts, data,information,database,...
Kskv kutch university DBMS unit 1 basic concepts, data,information,database,...
Dipen Parmar
 
Database Presentation
Database PresentationDatabase Presentation
Database Presentation
a9oolq8
 
DATA WAREHOUSING
DATA WAREHOUSINGDATA WAREHOUSING
DATA WAREHOUSING
King Julian
 
Parsing
ParsingParsing
Parsing
Roohaali
 

What's hot (20)

1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
 
Database Management System ppt
Database Management System pptDatabase Management System ppt
Database Management System ppt
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Data file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing filesData file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing files
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
DBMS _Relational model
DBMS _Relational modelDBMS _Relational model
DBMS _Relational model
 
MODULE 1_Introduction to Data analytics and life cycle..pptx
MODULE 1_Introduction to Data analytics and life cycle..pptxMODULE 1_Introduction to Data analytics and life cycle..pptx
MODULE 1_Introduction to Data analytics and life cycle..pptx
 
Ch 3 E R Model
Ch 3  E R  ModelCh 3  E R  Model
Ch 3 E R Model
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
 
Client Server Computing : unit 1
Client Server Computing : unit 1Client Server Computing : unit 1
Client Server Computing : unit 1
 
Web mining (structure mining)
Web mining (structure mining)Web mining (structure mining)
Web mining (structure mining)
 
Edi layer
Edi layerEdi layer
Edi layer
 
System and its types
System and its typesSystem and its types
System and its types
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
 
Inter Organizational e-commerce
Inter Organizational e-commerceInter Organizational e-commerce
Inter Organizational e-commerce
 
Kskv kutch university DBMS unit 1 basic concepts, data,information,database,...
Kskv kutch university DBMS unit 1  basic concepts, data,information,database,...Kskv kutch university DBMS unit 1  basic concepts, data,information,database,...
Kskv kutch university DBMS unit 1 basic concepts, data,information,database,...
 
Database Presentation
Database PresentationDatabase Presentation
Database Presentation
 
DATA WAREHOUSING
DATA WAREHOUSINGDATA WAREHOUSING
DATA WAREHOUSING
 
Parsing
ParsingParsing
Parsing
 

Similar to R data interfaces

Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
NoSQLmatters
 
AZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxAZMS PRESENTATION.pptx
AZMS PRESENTATION.pptx
SonuShaw16
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache Drill
DataWorks Summit
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
 
Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)
Michael Rys
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
Rebecca Grenier
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
John David Duncan
 
Import web resources using R Studio
Import web resources using R StudioImport web resources using R Studio
Import web resources using R Studio
Rupak Roy
 
Local Storage
Local StorageLocal Storage
Local Storage
Ivano Malavolta
 
Data handling in r
Data handling in rData handling in r
Data handling in r
Abhik Seal
 
How Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill SetsHow Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill Sets
Chad Petrovay
 
PostgreSQL, MongoDb, Express, React, Structured
PostgreSQL, MongoDb, Express, React, StructuredPostgreSQL, MongoDb, Express, React, Structured
PostgreSQL, MongoDb, Express, React, Structured
priya951125
 
R Introduction
R IntroductionR Introduction
R Introduction
Sangeetha S
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
christkv
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache Drill
MapR Technologies
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptx
natesanp1234
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
Marco Gralike
 
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptxfINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
dataKarthik
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web apps
Ivano Malavolta
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFrames
Databricks
 

Similar to R data interfaces (20)

Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
 
AZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxAZMS PRESENTATION.pptx
AZMS PRESENTATION.pptx
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache Drill
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Import web resources using R Studio
Import web resources using R StudioImport web resources using R Studio
Import web resources using R Studio
 
Local Storage
Local StorageLocal Storage
Local Storage
 
Data handling in r
Data handling in rData handling in r
Data handling in r
 
How Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill SetsHow Clean is your Database? Data Scrubbing for all Skill Sets
How Clean is your Database? Data Scrubbing for all Skill Sets
 
PostgreSQL, MongoDb, Express, React, Structured
PostgreSQL, MongoDb, Express, React, StructuredPostgreSQL, MongoDb, Express, React, Structured
PostgreSQL, MongoDb, Express, React, Structured
 
R Introduction
R IntroductionR Introduction
R Introduction
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache Drill
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptx
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
 
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptxfINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
 
Local storage in Web apps
Local storage in Web appsLocal storage in Web apps
Local storage in Web apps
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFrames
 

Recently uploaded

一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
bmucuha
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
hyfjgavov
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
Vineet
 
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdfreading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
perranet1
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
Vineet
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
Timothy Spann
 
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
Rebecca Bilbro
 
Q4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slideQ4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slide
mukulupadhayay1
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
eoxhsaa
 
Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)
GeorgiiSteshenko
 
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
asyed10
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
hiju9823
 
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
agdhot
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
hqfek
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
actyx
 
Digital Marketing Performance Marketing Sample .pdf
Digital Marketing Performance Marketing  Sample .pdfDigital Marketing Performance Marketing  Sample .pdf
Digital Marketing Performance Marketing Sample .pdf
Vineet
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
Márton Kodok
 
Senior Engineering Sample EM DOE - Sheet1.pdf
Senior Engineering Sample EM DOE  - Sheet1.pdfSenior Engineering Sample EM DOE  - Sheet1.pdf
Senior Engineering Sample EM DOE - Sheet1.pdf
Vineet
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
z6osjkqvd
 

Recently uploaded (20)

一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
 
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdfreading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
 
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
 
Q4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slideQ4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slide
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
 
Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)
 
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
 
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
 
Digital Marketing Performance Marketing Sample .pdf
Digital Marketing Performance Marketing  Sample .pdfDigital Marketing Performance Marketing  Sample .pdf
Digital Marketing Performance Marketing Sample .pdf
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
 
Senior Engineering Sample EM DOE - Sheet1.pdf
Senior Engineering Sample EM DOE  - Sheet1.pdfSenior Engineering Sample EM DOE  - Sheet1.pdf
Senior Engineering Sample EM DOE - Sheet1.pdf
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
 

R data interfaces

  • 1. Presented by: 1) Bhavesh Sarvaiya(115347) 2) Naresh Sarvaiya(115340) R Data Interfaces
  • 2. Topics CSV Files Excel Files Database XML Files JSON Files Web Data Get Facebook data
  • 3. CSV Files How to Read CSV Files in R ?  The csv file is a text file in which the values in the columns are separated by a comma.  Each cell inside such data file is separated by a special character, which usually is a comma, although other characters can be used as well.  Example: student info "No", "Name", "age" 1,Bhavesh,22 2,Ramesh,20 3,Karmraj,22 • Copy it and paste into notepad and save as mydata.csv
  • 4. Continue… read.csv() • read.csv(file, header = TRUE, sep = ",", quote = """, dec = ".", comment.char = “-", ...) • The read.csv() function has a few important arguments: • file, the name of a file, or a connection • header, logical indicating if the file has a line • sep, a string indicating how the columns are separated • comment.char, a character string indicating the comment character. This defalts to "#". If there are no commented lines in your file, it’s worth setting this to be the empty string "". • skip, the number of lines to skip from the beginning • mydata = read.csv("mydata.csv") • print(mydata) No Name age 1 Bhavesh 22 2 Ramesh 20 3 Karmraj 22
  • 5. Continue… • print(is.data.frame(data)) = TRUE • print(ncol(data)) = 3 • print(nrow(data)) = 3 • Get the maximum age • age<- max(mydata$age) • print(age) write.csv() • write.csv(x, file = "", append = FALSE, quote = TRUE, sep = ",", eol = "n", na = "NA", dec = ".", row.names = TRUE, col.names = TRUE) • write.csv(mydata,file = "t.csv ") • write.csv(mydata,file = "t.csv",row.names = F)
  • 6. Excel Files How to Read Excel Files in R ?  Microsoft Excel is the most widely used spreadsheet program which stores data in the .xls or .xlsx format.  install.packages("xlsx")  Load the library into R workspace library("xlsx")  Example: employee info id name salary start_date dept 1 Rick 623.3 1/1/2012 IT 2 Dan 515.2 9/23/2013 Operations 3 Michelle 611 11/15/2014 IT 4 Ryan 729 5/11/2014 HR 5 Gary 843.25 3/27/2015 Finance 6 Nina 578 5/21/2013 IT 7 Simon 632.8 7/30/2013 Operations 8 Guru 722.5 6/17/2014 Finance Copy it and open microsoft excel and save as named input.xlsx
  • 7. Continue… read.xlsx() • read.xlsx(file, sheetIndex, sheetName = NULL, rowIndex = NULL, startRow = NULL, endRow=NULL, colIndex=NULL, as.data.frame = TRUE, header=TRUE, keepFormulas = FALSE) • data <- read.xlsx("input.xlsx", sheetIndex = 1) • print(data) write.xlsx() • write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ", eol = "n", na = "NA", dec = ".", row.names = TRUE, col.names = TRUE, qmethod = c("escape", "double"), fileEncoding = "") • write.xlsx(data,file = "new.xlsx",sheetName = "s1")
  • 8. Database  The data is Relational database systems are stored in a normalized format.  So, to carry out statistical computing we will need very advanced and complex Sql queries.  But R can connect easily to many relational databases like MySql, Oracle, Sql server etc. and fetch records from them as a data frame.  Once the data is available in the R environment, it becomes a normal R data set and can be manipulated or analyzed using all the powerful packages and functions.
  • 9. Continue.. RMySQL Package install.packages("RMySQL") • Opening and closing connections • mysqlconnection<-dbConnect(MySQL(),user="root",password = "mysql", dbname = "sakila", host = "localhost") • on.exit(dbDisconnect(mysqlconnection)) • Processing query results • List the tables available in this database. dbListTables(mysqlconnection)
  • 10. Continue.. • Get record from table • rs <- dbSendQuery(con, "select * from city limit 10;") • data <- fetch(rs, n=10) • Creating Tables in MySql • dbWriteTable(mysqlconnection,“mtcars",iris[1:10,]) • Inserting Data into the Tables • dbSendQuery(mysqlconnection, "insert into mtcars(row_names, mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb) values('New Mazda RX4 Wag', 21, 6, 168.5, 110, 3.9, 2.875, 17.02, 0, 1, 4, 4)" )
  • 11. Continue.. • Updating Rows in the Tables • dbSendQuery(mysqlconnection, "update mtcars set disp = 168.5 where hp = 110") • Dropping Tables in MySql • dbSendQuery(mysqlconnection, 'drop table if exists mtcars')
  • 12. XML Files • XML is a file format which shares both the file format and the data on the World Wide Web, intranets, and elsewhere using standard ASCII text. • You can read a xml file in R using the "XML" package. • install.packages("XML")  Input Data • Click below link to open xml file • Parts.xml • Then read the file from r
  • 13. Continue… • Reading XML File • xmlParse() • Give the input file name to the function. • result <- xmlParse(file = "parts.xml") • Exract the root node from the xml file. • rootnode <- xmlRoot(result) • Find number of nodes in the root. rootsize<-xmlSize(rootnode) • Get the first element of the first node. print(rootnode[[1]][[1]])
  • 14. Continue… • XML to Data Frame • xmlToDataFrame() • Convert the input xml file to a data frame. • xmldataframe <- xmlToDataFrame(“parts.xml") • print(xmldataframe)
  • 15. JSON Files • JSON file stores data as text in human-readable format. • Json stands for JavaScript Object Notation. • R can read JSON files using the rjson package. • You can read a Json file in R using the "rjson" package. • install.packages(“rjson") Input Data Copy following data and paste into notepad and save as rjsonfile.json { "ID":["1","2","3","4","5","6","7","8" ], "Name":["bhavesh", "kiran", "mital", "yograj", "ramesh", "gita", "manan", "sital" ], "Salary":["623.3","515.2","611","729","843.25","578","632.8","722 .5" ], "StartDate":[1/1/2012","9/23/2013","11/15/2014","5/11/2014","3/27 /2015","5/21/2013", "7/30/2013","6/17/2014"], "Dept":["IT","Operations","IT","HR","Finance","IT","Operations"," Finance"] }
  • 16. Continue…. • Reading JSON File • FromJSON() • Give the input file name to the function. • result <- fromJSON(file = "rjsonfile.xml") • Print(result) • Convert JSON to a Data Frame • We can convert the extracted data above to a R data frame for further analysis the as.data.frame() function. • json_data_frame <- as.data.frame(result) • print(json_data_frame)
  • 17. Web Data • Many websites provide data for consumption by its users. • For example the World Health Organization(WHO) provides reports on health and medical information in the form of CSV, txt and XML files. • Using R programs, we can programmatically extract specific data from such websites. • Some packages in R which are used to scrap data form the web are − "RCurl",XML", and "stringr". • Install R Packages • install.packages("RCurl") • install.packages("XML") • install.packages("stringr") • install.packages("plyr")
  • 18. Continue… • Input Data • We will use the function getHTMLLinks() to gather the URLs of the files. • Then we will use the function download.file() to save the files to the local system. • url <- http://gujaratvidyapith.org/ • Gather the html links present in the webpage. • links <- getHTMLLinks(url) • Identify only the links which point to the JCMB 2017 files. • filenames <- links[str_detect(links, "JCMB_2017")] • Store the file names as a list. • filenames_list <- as.list(filenames)
  • 19. Continue… • Input Data • Create a function to download the files by passing the URL and filename list. downloadcsv <- function (url,filename) { filedetails <- str_c(url,filename) download.file(filedetails,filename) } • Now apply downloadcsv function and save the files into the current R working directory. downloadcsv(url,filename)
  • 20. Get Facebook data • Step 1 : Facebook Developer Registration • Go to https://developers.facebook.com and register yourself by clicking on Get Started button • Step 2 : Add a new App • click on My Apps button. Then select Add a New App from the drop down. • Step 3 : Get App ID and App Secret • Step 4 : OAuth Settings 1. On the left hand side menu, click on Add Product Button 2. Click on Facebook Login link 3. Under Settings, make sure YES is selected in Client OAuth Login 4. Type http://localhost:1410/ in Valid OAuth redirect URIs box 5. Click on Save Changes button
  • 21. Continue… • Install required packages • install.packages("Rfacebook") • install.packages("RCurl") • Paste your app id and app secret below • fb_oauth <- fbOAuth(app_id="183xxxxxxxx3748", app_secret="7bfxxxxxxxxcf0",extended_permissions = TRUE) • Check your profile account information • me <- getUsers("me",token=fb_oauth, private_info=TRUE) • me$name
  • 22. Continue… • List of all the pages you have liked • likes = getLikes(user="me", token = tt) • sample(likes$names, 10) • Extract list of posts from a Facebook page • page <- getPage(page="bbcnews", token=tt, n=200) • Which of these posts got maximum likes? • summary = page[which.max(page$likes_count),] • summary$message