DA Lab 1-7
DA Lab 1-7
Experiment-01
Object:-To get the input from user and perform numerical operations (MAX, MIN,
AVG, SUM, SQRT, ROUND) using in R.
#Program
numbers <- c(2,4,6,8,10)
max(numbers)
max(characters)
min(numbers)
sum(numbers)
sqrt(numbers)
mean(numbers)
OUTPUT:
[1]10
[1]"s"
[1] 2
[1] 30
[1] 6
1
KIT-651 DATA ANALYTICS LAB
2
KIT-651 DATA ANALYTICS LAB
Experiment-02
Object:-To perform data import or export (.csv, .xls ,.txt ) operation using
dataframe in R language.
Output
work_year experience_level employment_type
1 2023 SE FT
2 2023 MI CT
3 2023 MI CT
4 2023 SE FT
5 2023 SE FT
6 2023 SE FT
7 2023 SE FT
8 2023 SE FT
9 2023 SE FT
10 2023 SE FT
3
KIT-651 DATA ANALYTICS LAB
Output
Output:
4
KIT-651 DATA ANALYTICS LAB
5
KIT-651 DATA ANALYTICS LAB
Experiment-03
Object:-To get the input matrix from user and perform Matrix addition, subtraction,
multiplication, inverse transpose and division operations using vector concept in R.
#Program
print("Matrix-1:")
print(m1)
print("Matrix-2:")
print(m2)
result = m1 + m2
print("Result of addition")
print(result)
result = m1 - m2
print("Result of subtraction")
print(result)
result = m1 * m2
print("Result of multiplication")
print(result)
result = m1 / m2
print("Result of division:")
print(result)
6
KIT-651 DATA ANALYTICS LAB
OUTPUT :
[1] "Matrix-1:"
[1,] 1 3 5
[2,] 2 4 6
[1] "Matrix-2:"
[1,] 0 2 0
[2,] 1 3 2
[1,] 1 5 5
[2,] 3 7 8
[1,] 1 1 5
[2,] 1 1 4
[1,] 0 6 0
[2,] 2 12 12
[2,] 2 1.333333 3
7
KIT-651 DATA ANALYTICS LAB
8
KIT-651 DATA ANALYTICS LAB
Experiment-04
#Program
marks <- c(97, 78, 57, 64, 87)
result <- mean(marks)
print(result)
mode = function() {
return(names(sort(-table(marks)))[1])
}
mode()
OUTPUT:
[1] 76.6
[1] 78
[1] "78"
9
KIT-651 DATA ANALYTICS LAB
10
KIT-651 DATA ANALYTICS LAB
Experiment-05
#Program
print("Original Data:")
print(mydata)
print(mydata)
Output:
[1]"Original Data:"
x y
1 1 6
2 2 7
3 NA 8
4 4 NA
5 5 10
[1] "Data after removing missing values:"
x y
11 6
22 7
5 5 10
11
KIT-651 DATA ANALYTICS LAB
12
KIT-651 DATA ANALYTICS LAB
Min-Max Normalization:
Program:
# Create a vector of data
print("Original Data:")
print(mydata)
print(mydata_normalized)
Output:
[1] 1 2 3 4 5
[,1]
[1,] 0.00
[2,] 0.25
[3,] 0.50
[4,] 0.75
[5,] 1.00
attr(,"scaled:center")
[1] 1
attr(,"scaled:scale")
[1] 4
13
KIT-651 DATA ANALYTICS LAB
14
KIT-651 DATA ANALYTICS LAB
Experiment:6
Object: To perform dimensionality reduction operation using PCA
for house's dataset using R language with output.
#Program
# Loading Data
data(mtcars)
# Summary
summary(my_pca)
my_pca
# Compute variance
my_pca.var <- my_pca$sdev ^ 2
my_pca.var
15
KIT-651 DATA ANALYTICS LAB
rpart.plot(rpart.model)
16
KIT-651 DATA ANALYTICS LAB
OUTPUT
Rscript /tmp/pkYpkkGJLy.r
[1] "sdev" "rotation" "center" "scale" "x"
Importance of components:
PC1 PC2 PC3 PC4 PC5 PC6 PC7
Standard deviation 2.5707 1.6280 0.79196 0.51923 0.47271 0.46000 0.3678
Proportion of Variance 0.6008 0.2409 0.05702 0.02451 0.02031 0.01924 0.0123
Cumulative Proportion 0.6008 0.8417 0.89873 0.92324 0.94356 0.96279 0.9751
PC8 PC9 PC10 PC11
Standard deviation 0.35057 0.2776 0.22811 0.1485
Proportion of Variance 0.01117 0.0070 0.00473 0.0020
Cumulative Proportion 0.98626 0.9933 0.998001.0000
Standard deviations (1, .., p=11):
[1]2.5706809 1.6280258 0.7919579 0.5192277 0.4727061 0.4599958 0.3677798
[8] 0.3505730 0.2775728 0.2281128 0.1484736
17
KIT-651 DATA ANALYTICS LAB
18
KIT-651 DATA ANALYTICS LAB
19
KIT-651 DATA ANALYTICS LAB
20
KIT-651 DATA ANALYTICS LAB
21
KIT-651 DATA ANALYTICS LAB
EXPERIMENT NO - 7
Output
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-38.4551 0.6746
22
KIT-651 DATA ANALYTICS LAB
Output
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-6.3002 -1.6629 0.0412 1.8944 3.9775
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -38.45509 8.04901 -4.778 0.00139 **
x 0.67461 0.05191 12.997 1.16e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
23
KIT-651 DATA ANALYTICS LAB
Output
76.22869
24
KIT-651 DATA ANALYTICS LAB
Live Demo
Output
25
KIT-651 DATA ANALYTICS LAB
26