Galgotias College of Engineering & Technology: Inroduction To Data Analytics and Visualization Lab File (KDS-551)
Galgotias College of Engineering & Technology: Inroduction To Data Analytics and Visualization Lab File (KDS-551)
Batch (D1/D2) D1
Submitted by
PRAMIT KUMAR SAMANT
INDEX
Experiment Experiment Name Date of Date of Grade Faculty
No. Conduction Submission Signature
Program-
#Create a Vector
> data=c(23,4,56,21,34,56,73)
> #Get the maximum value
> print(max(data))
[1] 73
> #Get the minimum value
> print(min(data))
[1] 4
> #Get the SUM-
> sum(data)
[1] 267
> #Get the AVG-
> print(mean(data))
[1] 38.14286
> #Get the SQRT-
> a=5
> print(sqrt(a))
[1] 2.236068
> a=5.2
> #Get the ROUND-
> print(round(a))
[1] 5
Program-
#.CSV
> read.data<-read.csv("C:/Users/sidsh/OneDrive/Desktop/College Work/5th-
Semester/D.A.V Lab/business-financial-data-june-2023-quarter-csv.csv")
> print(read.data)
#.XLS
> install.packages("readxl")
> library(readxl)
> excel_data <-
read_excel("C:/Users/sidsh/Downloads/file_example_XLS_10.xls")
> print(excel_data)
#.TXT
> txt_data <- read.table("C:/Users/sidsh/OneDrive/Desktop/R_Language.txt",
header = TRUE, sep = "\t")
> print(excel_data)
XML FILE-
TXT FILE-
OBJECTIVE- To get the input matrix from user and perform Matrix addition,
subtraction, multiplication, inverse transpose and division operations using
vector concept in R.
Program-
#MATRIX CREATION
> {r = readline("Enter the number of rows:")}
> r = as.integer(r)
> {c = readline("Enter the number of columns:")}
> c = as.integer(c)
#MTRIX VALUES:
> A = scan()
> B = scan()
> M1 = matrix(A,nrow = r,ncol = c,byrow = TRUE)
> M2 = matrix(B,nrow = r,ncol = c,byrow = TRUE)
#MATRIX M1:
> print(M1)
#MATRIX M2:
> print(M2)
#1.ADDITION-
> print(M1+M2)
#2.SUBTRACTION-
>print(M1-M2)
#3.MULTIPLICATION-
>print(M1*M2)
Program-
# DEFINING VECTOR
> a=c(23,84,16,95,23,6,41,29,6,4,6)
#1.MEAN-
> print(mean(a))
#2.MEDIAN-
> print(median(a))
#3.MODE-
> getmode <- function(a) {
uniqv <- unique(a)
uniqv[which.max(tabulate(match(a, uniqv)))]
}
> print(getmode(a))
#4.STANDARD DEVIATION-
> print(sd(a))
PROGRAM-5
PROGRAMMED BY- HIMANSHU UPADHYAY
OBJECTIVE- To perform data pre-processing operation (1) Handle mining data
(2) Min-Max normalization
Program-
#Handle Mining Data-
x = c(NA,3,4,NA,NA,NA)
is.na(x)
x = c(NA,3 4,NA,NA,0/0,0/0)
is. nan (x)
#Min-Max Normlization-
install.packages("caret")
library(caret)
data = data.frame(Var1 = c(120, 345, 145, 522, 596, 285, 21), Var2 = c(10,
15, 45, 22, 53, 28, 12), Var3 = c(-34, 0.05, 0-15, 0-12, -6, 0·85, 0.11))
Sample Output-
Program-
> data("USArrests")
> rawdf <- na.omit(USArrests)
> names(rawdf)=c("Murder","Assault", "Assasination”, "UrbanPop")
> head(rawdf)
> arrests.pca <- prcomp(scale(USArrests),center = TRUE)
> names(arrests.pca)
> print(arrests.pca)
> summary(arrests.pca)
> pcaCharts(arrests.pca)
> biplot(arrests.pca,scale=0, cex=.7)
> pca.out <- arrests.pca
> pca.out$rotation <- -pca.out$rotation
> pca.out$x <- -pca.out$x
> biplot(pca.out,scale=0, cex=.7)
> pca.out$rotation[,1:2]
Sample Output-
Program-
#Create the predictor and response variable:
Sample Output-
library(arulesViz)
library(RColorBrewer)
data("Groceries")
inspect(rules[1:10])
type = "relative",
Output –
Batch (D1/D2) D2
Program-
#Create a Vector
> data=c(23,4,56,21,34,56,73)
> print(max(data))
[1] 73
> print(min(data))
[1] 4
> sum(data)
[1] 267
> print(mean(data))
[1] 38.14286
> a=5
> print(sqrt(a))
[1] 2.236068
> a=5.2
> print(round(a))
[1] 5
Program-
#.CSV
> read.data<-read.csv("C:/Users/sidsh/OneDrive/Desktop/College Work/5th-
Semester/D.A.V Lab/business-financial-data-june-2023-quarter-csv.csv")
> print(read.data)
#.XLS
> install.packages("readxl")
> library(readxl)
> excel_data <-
read_excel("C:/Users/sidsh/Downloads/file_example_XLS_10.xls")
> print(excel_data)
#.TXT
> txt_data <- read.table("C:/Users/sidsh/OneDrive/Desktop/R_Language.txt",
header = TRUE, sep = "\t")
> print(excel_data)
XML FILE-
TXT FILE-
Program-
#MATRIX CREATION
> {r = readline("Enter the number of rows:")}
> r = as.integer(r)
> {c = readline("Enter the number of columns:")}
> c = as.integer(c)
#MTRIX VALUES:
> A = scan()
> B = scan()
> M1 = matrix(A,nrow = r,ncol = c,byrow = TRUE)
> M2 = matrix(B,nrow = r,ncol = c,byrow = TRUE)
#MATRIX M1:
> print(M1)
#MATRIX M2:
> print(M2)
#1.ADDITION-
> print(M1+M2)
#2.SUBTRACTION-
>print(M1-M2)
#3.MULTIPLICATION-
>print(M1*M2)
Program-
# DEFINING VECTOR
> a=c(23,84,16,95,23,6,41,29,6,4,6)
#1.MEAN-
> print(mean(a))
#2.MEDIAN-
> print(median(a))
#3.MODE-
> getmode <- function(a) {
uniqv <- unique(a)
uniqv[which.max(tabulate(match(a, uniqv)))]
}
> print(getmode(a))
#4.STANDARD DEVIATION-
> print(sd(a))
Sample Output-
Program-
#Handle Mining Data-
x = c(NA,3,4,NA,NA,NA)
is.na(x)
x = c(NA,3 4,NA,NA,0/0,0/0)
is. nan (x)
#Min-Max Normlization-
install.packages("caret")
library(caret)
data = data.frame(Var1 = c(120, 345, 145, 522, 596, 285, 21), Var2 = c(10,
15, 45, 22, 53, 28, 12), Var3 = c(-34, 0.05, 0-15, 0-12, -6, 0·85, 0.11))
Sample Output-
Program-
> data("USArrests")
> names(arrests.pca)
> print(arrests.pca)
> summary(arrests.pca)
> pcaCharts(arrests.pca)
> biplot(arrests.pca,scale=0, cex=.7)
> pca.out <- arrests.pca
> pca.out$rotation <- -pca.out$rotation
> pca.out$x <- -pca.out$x
> biplot(pca.out,scale=0, cex=.7)
> pca.out$rotation[,1:2]
Sample Output-
Program-
#Create the predictor and response variable:
> x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
> y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
> relation <- lm(y~x)
#Give the chart file a name:
> png(file = "linearregression.png")
#Plot the chart:
> plot(y,x,col = "blue",main = "Height & Weight Regression",
abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in Kg",ylab = "Height in
cm")
#Save the file:
> dev.off()
Sample Output-
library(arulesViz)
library(RColorBrewer)
data("Groceries")
inspect(rules[1:10])
type = "relative",
Output –
Program-
>install.packages(“stats”)
>install.packages(“cluster”)
>install.packages(“ClusterR”)
>library(stats)
>library(cluster)
>library(ClusterR)
> kmeans.re
> kmeans.re$cluster
> cm
+ col = kmeans.re$cluster)
+ col = kmeans.re$cluster,
> kmeans.re$centers
+ y_kmeans,
+ lines = 0,
+ shade = TRUE,
+ color = TRUE,
+ labels = 2,
+ plotchar = FALSE,
+ span = TRUE,
+ xlab = 'Sepal.Length',
+ ylab = 'Sepal.Width')
Sample Output-
Program-
>install.packages("class")
>install.packages("ggplot2")
>library(class)
>library(ggplot2)
>k <- 3
>print(results)
x = "Actual Diagnosis",
y = "Count",
theme_minimal()
Program-
> library(ggplot2)
Sample Output-
Program-
> install packages(“party”)
> library(party)
> print(head(readingSkill))
>plot(output.tree)
>dev.off()
Sample Output-
Program-
> install packages(“party”)
> library(party)
> print(head(readingSkill))
>plot(output.tree)
>dev.off()
Sample Output-