Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

R programming lab sample, Schemes and Mind Maps of Relational Database Management Systems (RDBMS)

R programming lab sample source code

Typology: Schemes and Mind Maps

2023/2024

Uploaded on 07/03/2025

rajkumar-8
rajkumar-8 🇮🇳

1 document

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
SRI RAMAKRISHNA MISSION VIDYALAYA
COLLEGE OF ARTS AND SCIENCE
[AUTONOMOUS]
Accredited by NAAC with A Grade
Coimbatore – 641 020
APR– 2025
DEPARTMENT OF COMPUTER APPLICATIONS
NAME :
REG. NO :
SEMESTER : IV
SUBJECT :NME: Data Science and Big data Analytics
SUBJECT CODE :20UCA4NM2
SRI RAMAKRISHNA MISSION VIDYALAYA
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download R programming lab sample and more Schemes and Mind Maps Relational Database Management Systems (RDBMS) in PDF only on Docsity!

SRI RAMAKRISHNA MISSION VIDYALAYA

COLLEGE OF ARTS AND SCIENCE

[AUTONOMOUS]

Accredited by NAAC with A Grade

Coimbatore – 641 020

APR– 2025

DEPARTMENT OF COMPUTER APPLICATIONS

NAME :

REG. NO :

SEMESTER : IV

SUBJECT :NME: Data Science and Big data Analytics

SUBJECT CODE :20UCA4NM

SRI RAMAKRISHNA MISSION VIDYALAYA

COLLEGE OF ARTS AND SCIENCE

[AUTONOMOUS]

Accredited by NAAC with A Grade

Coimbatore – 641 020

DEPARTMENT OF COMPUTER APPLICATIONS

BONAFIDE CERTIFICATE

REGISTER NO:______________

This is to certify that it is a bonafide record work done by

_______________________ in “NME: Data Science and Big data AnalyticsLab”(20UCA4NM2) for the IV Semester during the Academic year

2021 - 2022. Submitted for the Semester Practical Examinations held on

______________.

Head of the Department Staff in Charge

Internal Examiner External Examiner

1. Adding two matrixes using array Aim To Perform a R Program on adding two matrixes using array Algorithm Step1: Start the Process Step2: Initialize two matrixes, and assign values in two different variables. Step3: print the addition of two matrixes as a result. Step 4: As in the same way of addition, we can subtract, multiply, and division process can be carried out. Step 5: print the result of subtracted, multiplied and divided values of two matrix. Step 6: Stop the process

R Program

  1. Create two 2x3 matrixes.

  2. m1 =matrix(c( 1 , 2 , 3 , 4 , 5 , 6 ),nrow= 2 )
  3. print("Matrix-1:")
  4. print(m1)
  5. m2 =matrix(c( 0 , 1 , 2 , 3 , 0 , 2 ),nrow= 2 )
  6. print("Matrix-2:")
  7. print(m2)
  8. result = m1 + m
  9. print("Result of addition")
  10. print(result)
  11. result = m1 - m
  12. print("Result of subtraction")
  13. print(result)
  14. result = m1 * m
  15. print("Result of multiplication")
  16. print(result)
  17. result = m1 / m
  18. print("Result of division:")
  19. print(result)

Output Screen

[1] "Matrix-1:"

[,1] [,2] [,3]

[1,] 1 3 5

[2,] 2 4 6

[1] "Matrix-2:"

[,1] [,2] [,3]

[1,] 0 2 0

[2,] 1 3 2

[1] "Result of addition"

[,1] [,2] [,3]

[1,] 1 5 5

2.Simple Calculator

Aim To Perform a R Program on arithmetic operations as a simple calculator. Algorithm Step1: Start the Process Step2: Initialize add, subtract, multiply and division function to perform the addition, subtraction, multiplication and division operations Step3: Getting a input of two numbers for the arithmetic operation as a integer value. Step4: Execute the program to perform the arithmetic operation and we can get the output. Step5: Stop the process

R Program

  1. add <- function(x, y) {
  2. return(x + y)
  3. }
  4. subtract <- function(x, y) {
  5. return(x - y)
  6. }
  7. multiply <- function(x, y) {
  8. return(x * y)
  9. }
  10. divide <- function(x, y) {
  11. return(x / y)
  12. }
  13. take input from the user

  14. print("Select operation.")
  15. print("1.Add")
  16. print("2.Subtract")
  17. print("3.Multiply")
  18. print("4.Divide")
  19. choice = as.integer(readline(prompt="Enter choice[1/2/3/4]: "))
  20. num1 = as.integer(readline(prompt="Enter first number: "))
  21. num2 = as.integer(readline(prompt="Enter second number: "))
  22. operator <- switch(choice,"+","-","*","/")
  23. result <- switch(choice, add(num1, num2), subtract(num1, num2), multiply(num1, num2), divide(num1, num2))
  24. print(paste(num1, operator, num2, "=", result))

3.Multiplication Table

Aim To Perform a R Program on print the Multiplication table from the given number. Algorithm Step1: Start the Process Step2: Initialize the variable, for print the multiplication table. Step3: To print the multiplication table, we can use the for-loop statement. Step4: Using with the for-loop statement increment the variable value. Step5: Print the given value and also print the given number multiplication table. Step6. Stop the Process.

R Program

R Program to find the multiplicationtable (from 1 to 10)

take input from the user

num = as.integer(readline(prompt = "Enter a number: "))

use for loop to iterate 10 times

for(i in 1:10) { print(paste(num,'x', i, '=', num*i)) }

Output:

Enter a number: 7 [1] "7 x 1 = 7" [1] "7 x 2 = 14" [1] "7 x 3 = 21" [1] "7 x 4 = 28" [1] "7 x 5 = 35" [1] "7 x 6 = 42" [1] "7 x 7 = 49" [1] "7 x 8 = 56" [1] "7 x 9 = 63" [1] "7 x 10 = 70" Result Thus, the program was successfully verified and Executed

R Program

x =c(10,20,30)

print("Sum:")

print(sum(x))

print("Mean:")

print(mean(x))

print("Product:")

print(prod(x))

Output:

[1] "Sum:"

[1] 60

[1] "Mean:"

[1] 20

[1] "Product:"

[1] 6000

Result Thus, the program was successfully verified and Executed

5. To Convert Decimal into Binary using Recursive Aim To Perform a R Program on Decimal into Binary using Recursive Algorithm STEP 1: Call function convert_to_binary() STEP 2: Pass the decimal number which needs to be converted to binary as decnum to the function. STEP 3: inside the function check if the given number is greater than 1, if yes call function convert_to_binary() again with decnum/2 as the argument STEP 4: divide the number decnum successively by 2 and print the remainder

6. K-Means clustering technique.

Aim To Perform a R Program on K-means clustering technique. Algorithm Step 1: Installing the relevant packages and calling their libraries Step 2: Loading and making sense of the dataset. Step 3: Eliminating the target variable Step 4: The elbow point technique Step 5: Implementing K-means Step 6: Plotting our data-points in clusters Step 7: Kmeans with K = 3 Step 8: Plotting the new clustered graph

R Program

Installing Packages

install.packages("ClusterR") install.packages("cluster")

Loading package

library(ClusterR) library(cluster)

Removing initial label of

Species from original dataset

iris_1 < - iris[, - 5 ]

Fitting K-Means clustering Model

to training dataset

set.seed( 240 ) # Setting seed kmeans.re < - kmeans(iris_1, centers = 3 , nstart = 20 ) kmeans.re

Cluster identification for

each observation

kmeans.re$cluster

Confusion Matrix

cm < - table(iris$Species, kmeans.re$cluster) cm

Model Evaluation and visualization

plot(iris_1[c("Sepal.Length", "Sepal.Width")]) plot(iris_1[c("Sepal.Length", "Sepal.Width")], col = kmeans.re$cluster) plot(iris_1[c("Sepal.Length", "Sepal.Width")], col = kmeans.re$cluster, main = "K-means with 3 clusters")

Plotiing cluster centers

kmeans.re$centers kmeans.re$centers[, c("Sepal.Length", "Sepal.Width")]

cex is font size, pch is symbol

points(kmeans.re$centers[, c("Sepal.Length", "Sepal.Width")], col = 1 : 3 , pch = 8 , cex = 3 )

Visualizing clusters

y_kmeans< - kmeans.re$cluster clusplot(iris_1[, c("Sepal.Length", "Sepal.Width")], y_kmeans, lines = 0 , shade = TRUE,

Output:

● Model kmeans_re:

The 3 clusters are made which are of 50, 62, and 38 sizes respectively.

Within the cluster, the sum of squares is 88.4%.

● Cluster identification:

● Confusion Matrix:

● K-means with 3 clusters plot:

● Plotting cluster centers:

● Plot of clusters:

Result Thus, the program was successfully verified and Executed