Session 12
Session 12
Session-12
SQL and Regression
> setwd("F:/da2024")
> setwd("~/")
> getwd()
[1] "F:/da2024"
getwd()
"C:/Users/PRS/Documents"
Indian Institute of Management Rohtak
Workspace and Working Directory
Similarly, to read .csv files the read.csv() function can be used to read in the data frame
directly
library("readxl")
airqual <-
read_excel("C:\\Users\\admin\\Desktop\\BA_Gradesheet.
xlsx")
Indian Institute of Management Rohtak
Import Data (input.csv)
View(data)
Practices
Paste your input.csv file in working directory
data <- read.csv("input.csv")
print(data)
# Get the max salary from data frame.
sal <- max(data$salary)
print(sal)
[1] 843.25
Get the details of the person with max salary
# Get the person detail having max salary.
retval <- subset(data, salary == max(salary))
print(retval)
library(sqldf)
Crashes.xlsx
Indian Institute of Management Rohtak
Indian Institute of Management Rohtak
crash <- read.csv("crashes.csv")
OR
p1 <- read.csv("roads.csv")
OR
Crash
Indian Institute of Management Rohtak
#join the data sets
➢a<-sqldf("select * from
crash join p1 on
crash.Road = p1.Road ")
➢ View(a)
data("UCBAdmissions")
View(ucb)
## total_ladies
## 1 1278
Indian Institute of Management Rohtak
Group by dept
https://dept.stat.lsa.umich.edu/~jerrick/courses/stat701/notes/sql.html
https://jasminedaly.com/tech-short-papers/sqldf_tutorial.html
SELECT *
FROM workson
WHERE hours < 10 AND resp
= 'Manager'
Indian Institute of Management Rohtak
Write an SQL query that returns the employees
(number and name only) who have a
title of 'EE' or 'SA' and make more than $35,000.
emp (eno, ename, bdate, title, salary, dno)
SELECT ename
FROM emp
WHERE dno = 'D1'
ORDER BY salary DESC
Indian Institute of Management Rohtak
Write an SQL query that returns the departments (all fields)
ordered by ascending department name.
SELECT *
FROM dept
ORDER BY dname ASC
Weight <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
=-38.45009+0.67461*170=76.23365
k1<-data.frame(Height=c(170,172,174,176,178))
> k1
Height
1 170 x14<-predict(relation,k1)
2 172
3 174
4 176
5 178 x14
Indian Institute of Management Rohtak
Visualize the Regression Graphically
# Give the chart file a name.
png(file = "linearregression.png") # Plot the chart.
plot(Height,Weight, abline(lm(Weight~Height)))
# Save the file.
dev.off() getwd()
plot(Height,Weight,col="blue",main="Height &
Weight Regression",
abline(lm(Weight~Height)),cex =
1.3,pch=16,xlab="Weight in Kg",ylab="Height in
cm")
Indian Institute of Management Rohtak
Indian Institute of Management Rohtak
plot(x,y,pch=2,cex=6,col="red") Indian Institute of Management Rohtak
plot(Height,Weight,pch=4,cex=7,col="red")
View(input)
a <- data.frame(disp=221,hp=102,wt=2.91)
> print(result)
22.65987
x[-c(1,3), ]
Indian Institute of Management Rohtak
Thank you !!!
Indian Institute of Management Rohtak