R Lab PGM
R Lab PGM
R TOOL
Aim:
To Write a R program to find Sum, Mean and Product of Vector in R.
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 3: Use the functions sum (), mean (), product () to calculate the vector.
Step 5: Run the program in the R Console using source (“E:\\ R tool\\smp.r")
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:2 Sample from a Population
Date:20.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 4: Use the dataframe() function to create dataframe() of the given values.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\pop.r").
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:3 Sort a Vector
Date:23.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\sort.r").
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:4
combine the matrix using rbind and cbind methods
Date:23.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 6: Run the program for R Console using source (“E:\\ R tool\\matrix.r").
m1<- matrix(c(20:28),nrow=3,ncol=3,byrow=TRUE)
m2<- matrix(c(30:38),nrow=3,ncol=3,byrow=TRUE)
x<- cbind(m1,m2)
y<- rbind(m1,m2)
Result:
Thus the above program has been executed and verified successfully.
EX.No:5
Use seq() to create sequence
Date:23.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 4: Use the inbuild seq() function to create sequence of the values.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\seq.r").
a<-as.integer(readline("enter
as.integer(readline("enter the Starting element : "))
b<-as.integer(readline("enter
as.integer(readline("enter the Ending element : "))
c<-as.integer(readline("enter
as.integer(readline("enter the increasing element : "))
cat(seq(a,b,c),"\n")
Output:
Result:
Thus the above program has been executed and verified successfully.
successfu
EX.No:6
convert the table data into data frame
Date:28.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 4: Use the dataframe() function to convert table data to data frame.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\data.r").
for(i in (1:n)) {
empno <- c(empno, as.integer(readline("Enter the employee number = ")))
ename <- c(ename, readline("Enter the employee name = "))
sal <- c(sal, as.integer(readline("Enter the salary = ")))
}
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:7 Calculate student mark list and output it in data frame
Date:28.01.2025
Aim:
frame.
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 4: Use the dataframe() function to calculate student mark list and
Step 6: Run the program for R Console using source (“E:\\ R tool\\student.r").
print("DATA FRAME")
for (i in (1:n)) {
rno <- c(rno, as.integer(readline("Enter Register No = ")))
name <- c(name, readline("Enter Name = "))
m1 <- c(m1, as.integer(readline("Enter M1 = ")))
m2 <- c(m2, as.integer(readline("Enter M2 = ")))
m3 <- c(m3, as.integer(readline("Enter M3 = "))) }
total <- m1 + m2 + m3
avg <- total / 3
print(x)
Output:
Result:
Thus the above program has been executed and verified.
verified
EX.No:8 Check Prime Number
Date:31.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Number.
Step 6: Run the program for R Console using source (“E:\\ R tool\\prime.r").
if (n <= 1)
{
print(paste("Given number", n, "is neither prime nor composite."))
} else if (n == 2)
{
print(paste("Given number", n, "is the only even prime number."))
} else if (any(n %% 2:(n-1)
2:(n == 0))
{
print(paste("Given number", n, "is not Prime."))
} else
{
print(paste("Given number", n, "is Prime."))
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:9 Check for Leap Year
Date:31.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 6: Run the program for R Console using source (“E:\\ R tool\\leep.r").
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:10 Check if a Number is Odd or Even
Date:31.01.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 4: use shift operator to check the given number is odd or even.
Step 6: Run the program for R Console using source (“E:\\ R tool\\odd.r").
print("ODD OR EVEN")
print("-----------")
if (a %% 2 == 0)
{
cat("Given number", a, "is Even.\n")
Even.
} else
{
cat("Given number", a, "is Odd.\n")
Odd.
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:11 Find the Sum of Natural Numbers
Date:05.02.2025
Aim:
Algorithm:
Step2: Open the R-GUI and click the New Script to type the program.
if(n < 0)
{
print("Enter a positive number")
} else
{
sum = (n*(n+1))/2;
print(paste("The sum
um is", sum))
}
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:12 Convert Decimal into Binary using Recursion
Date:05.02.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\binary.r").
b<- function(d)
{
if(d > 1)
b(d%/%2)
cat(d %% 2)
}
n<-as.integer(readline("enter
as.integer(readline("enter the number : "))
cat(b(a),"binary value for the ",n,"
",n,"\n")
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:13 Find the Factorial of a Number Using Recursion
Date:10.02.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\fact.r").
n<-as.integer(readline("enter
as.integer(readline("enter the number : "))
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:14 Make a Simple Calculator
Date: 10.02.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\calc.r").
Result:
Thus the above program has been executed and verified successfully.
EX.No:15 Import CSV data into R
Date:10.02.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 3: open notepad and type the student values and save with std.csv file
format.
Step 4: give the path of the csv file and import the csv file.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\csv.r").
x<-read.csv("E:\\msc\\MSC
MSC 2nd sem
sem\\DM LAB\\R tool\\std.csv")
print(x)
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:16 Move the result data from R to CSV
Date: 14.02.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\calc.r").
for(i in (1:n))
{
empno <- c(empno, as.integer(readline("Enter the employee number = ")))
ename <- c(ename, readline("Enter the employee name = "))
sal <- c(sal, as.integer(readline("Enter the salary = ")))
da<-0.40*sal
ma<-0.10*sal
gpay<-sal+da+ma
}
Result:
Thus
hus the above program has been executed and verified successfully.
EX.No:17
Line Graph for Student Data
Date: 14.02.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 3: Give the range for the subject & give the marks.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\line.r").
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:18 Pie-Chart for Employee Data
Date: 19.02.2025
Aim:
Algorithm:
Step 2: Open the R-GUI and click the New Script to type the program.
Step 3: Give the input for salary & employee name for label variable.
Step 6: Run the program in the R Console using source (“E:\\ R tool\\pie.r").
print("-----PIE CHART-----")
n <- as.integer(readline("Enter no. of employees: "))
emp <- c()
name <- c()
# Input: Employee details
for (i in 1:n) {
cat("Enter details of Employee", i, ":\n")
name <- c(name, readline("Name: "))
emp <- c(emp, as.integer(readline("Salary: ")))
}
# Generate colors for each employee
colors <- rainbow(n)
pie(emp, main = "SALARY DETAILS", labels = name, col = colors)
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:19 Existing dataset and draw a chart.
Date: 19.02.2025
Aim:
a chart.
Algorithm:
Step 3: Create a table using the table() function based on selected variables.
Step 4: Visualize the table data using appropriate chart types (e.g., bar plot or
pie chart).
Step 6: Run the program in the R Console using source (“E:\\ R tool\\pie.r").
.
Program:
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:20 K-Means Clustering on IRIS Dataset
Date: 21.02.2025
Aim:
Algorithm:
Sepal.Width).
Step 5: Plot the clusters using a scatter plot to visualize the results.
tool\\iris.r").
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:21 mtcar data set and perform analysis
Date: 21.02.2025
Aim:
statistical functions.
Algorithm:
Step 2: Open the R-GUI and click "New Script" to create a new file.
Step 3: Create a CSV file (e.g., mtcars_data.csv) using any text editor or
spreadsheet software.
Step 4: Save the file and specify its path in the R program.
Step 7: Visualize the data using graphs (e.g., histogram or scatter plot).
Program:
Output:
Result:
Thus the above program has been executed and verified successfully.
WEKA TOOL
EX.No:1 Preprocessing on dataset student.arff
DATE:26.02.2025
Aim:
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset student.arff into WEKA by clicking the "Open
file" button.
Step 4: Use the "Preprocess" tab to select and apply filters like "Remove",
@relation student
@attribute sid numeric
@attribute name {ajai,bala,karthi,janaki,jeya,vijaya}
@attribute S1 numeric
@attribute S2 numeric
@attribute S3 numeric
@attribute S4 numeric
@attribute S5 numeric
@attribute total numeric
@attribute result {pass,fail}
@data
1,ajai,60,55,45,50,40,250,pass
2,bala,60,55,45,40,40,240,pass
3,karthi,60,55,40,50,40,240,pass
4,janaki,60,55,30,50,40,235,fail
5,jeya,60,55,45,60,40,260,pass
6,vijaya,60,55,65,50,40,270,pass
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:2 Preprocessing on dataset labor.arff
DATE: 26.02.2025
Aim:
WEKA tool.
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset labor.arff into WEKA by clicking the "Open file"
button.
Step 4: Use the "Preprocess" tab to view the attributes and missing values.
Values".
@relation labour
@attribute eid numeric
@attribute name string
@attribute gender string
@attribute age numeric
@attribute working_hours numeric
@attribute shift {day,night}
@attribute sal numeric
@attribute education_allow {yes,no}
@data
101,suresh,male,45,8,day,18500,yes
102,anitha,female,37,6,day,25800,no
103,divya,female,28,6,night,26750,yes
104,jeya,female,30,8,day,28800,yes
105,ajith,male,38,6,night,35000,no
106,pradeep,male,28,8,day,25000,yes
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:3 Association rule process on dataset contact
Date: 03.03.2025 lenses.arff using apriori algorithm
Aim:
To demonstrate the association rule mining on the contactlenses.arff
dataset using the Apriori algorithm in WEKA.
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset contactlenses.arff by clicking the "Open file" button.
@relation contact-lenses
@attribute age {young, pre-presbyopic, presbyopic}
@attribute spectacle-prescrip {myope, hypermetrope}
@attribute astigmatim {no, yes}
@attribute tear-prod-rate {reduced, normal}
@attribute contact-lenses {soft, hard, none}
@data
young,myope,no,reduced,none
young,myope,no,normal,soft
young,myope,yes,normal,hard
young,hypermetrope,no,normal,soft
young,hypermetrope,yes,normal,hard
pre-presbyopic,myope,no,normal,soft
pre-presbyopic,myope,yes,normal,hard
pre-presbyopic,hypermetrope,no,normal,soft
pre-presbyopic,hypermetrope,yes,normal,hard
presbyopic,myope,no,normal,none
presbyopic,myope,yes,normal,hard
presbyopic,hypermetrope,no,normal,soft
presbyopic,hypermetrope,yes,normal,hard
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:4
Association Rule Process on Dataset test.arff
DATE: 03.03.2025 Using Apriori Algorithm
Aim:
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset test.arff by clicking the "Open file" button.
Step 7: Click the "Start" button to execute the algorithm and generate rules.
@relation attribute
@attribute bread{y,n}
@attribute jelly{y,n}
@attribute butter{y,n}
@attribute milk{y,n}
@attribute sugar{y,n}
@data
yyynn
ynynn
ynyyn
ynnyy
yynyn
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:5
DATE: 03.03.2025
Classification Rule Process on Dataset
student.arff Using J48 Algorithm
Aim:
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset student.arff by clicking the "Open file" button.
Step 7: Click the "Start" button to train and evaluate the classifier.
@relation student
@attribute age {<30,30-40,>40}
@attribute income {low,medium,high}
@attribute student {yes,no}
@attribute credit-rating {fair,excellent}
@attribute buyspc {yes,no}
@data
%
<30, high, no, fair, no
<30, high, no, excellent, no
30-40, high, no, fair, yes
>40, medium, no, fair, yes
>40, low, yes, fair, yes
>40, low, yes, excellent, no
30-40, low, yes, excellent, yes
<30, medium, no, fair, no
<30, low, yes, fair, no
>40, medium, yes, fair, yes
<30, medium, yes, excellent, yes
30-40, medium, no, excellent, yes
30-40, high, yes, fair, yes
>40, medium, no, excellent, no
%
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:6
Classification Rule Process on Dataset
DATE: employee.arff Using J48 Algorithm
Aim:
To demonstrate the classification rule mining on the employee.arff dataset using
the J48 algorithm in WEKA.
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset employee.arff by clicking the "Open file" button.
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:7
DATE: Classification Rule Process on Dataset
employee.arff Using ID3 Algorithm
Aim:
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
button.
split.
Data set
@relation employee
@attribute age{25,27,28,29,30,35,48}
@attribute salary{10k,15k,17k,20k,25k,30k,35k,32k}
@attribute performance{good,average,poor}
@data
25 10k poor
27 15k poor
27 17k poor
28 17k poor
29 20k average
30 25k average
29 25k average
30 20k average
35 32k good
35 35k good
48 32k good
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:8 Classification Rule Process on Dataset
DATE: employee.arff Using Naïve Bayes Algorithm
Aim:
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset employee.arff by clicking the "Open file" button.
Step 5: Select the Naïve Bayes algorithm from the classifier list.
@relation employee
@attribute age{25,27,28,29,30,35,48}
@attribute salary{10k,15k,17k,20k,25k,30k,35k,32k}
@attribute performance{good,average,poor}
@data
25 10k poor
27 15k poor
27 17k poor
28 17k poor
29 20k average
30 25k average
29 25k average
30 20k average
35 32k good
35 35k good
48 32k good
Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:9 Classification Rule Process on Dataset
DATE: employee.arff Using Naïve Bayes Algorithm
Aim:
algorithm in WEKA.
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset iris.arff by clicking the "Open file" button.
Step 5: Select the Simple K-Means algorithm from the list of clustering
algorithms.
Step 6: Configure the number of clusters to 3 (for the iris dataset) and other
parameters as needed.
@RELATION iris
@ATTRIBUTE sepallength REAL
@ATTRIBUTE sepalwidth REAL
@ATTRIBUTE petallength
tallength REAL
@ATTRIBUTE petalwidth REAL
@ATTRIBUTE class {Iris-setosa,Iris
setosa,Iris-versicolor,Iris-virginica}
@DATA
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
Output:
Result:
Thus the above program has been executed and verified
successfully.
EX.No:10
DATE: Clustering Rule Process on Dataset student.arff
Using Simple K-Means
Aim:
Algorithm:
Step 2: Open the WEKA GUI Chooser and click the Explorer option.
Step 3: Load the dataset student.arff by clicking the "Open file" button.
Step 5: Select the Simple K-Means algorithm from the list of clustering
algorithms.
Step 8: Analyze the clustering results, including the centroids and cluster
assignments.
@relation student
@attribute sid numeric
@attribute name {usha,hari,rajesh,kiran,giri,manash}
@attribute DM numeric
@attribute WT numeric
@attribute CN numeric
@attribute AI numeric
@attribute STM numeric
@attribute total numeric
@attribute result {pass,fail}
@data
1,usha,60,55,45,50,40,250,pass
2,hari,60,55,45,40,40,240,pass
3,rajesh,60,55,40,50,40,240,pass
4,kiran,60,55,30,50,40,235,fail
2,giri,60,55,45,60,40,260,pass
3,manash,60,55,65,50,40,270,pass
Output:
Result:
Thus the above program has been executed and verified
successfully.
Filename: INDEX
Directory: C:\Users\lenovo\OneDrive\Documents
Template: C:\Users\lenovo\AppData\Roaming\Microsoft\Templates\Normal.dotm
Title:
Subject:
Author: lenovo
Keywords:
Comments:
Creation Date: 1/21/2025 7:44:00 PM
Change Number: 35
Last Saved On: 3/11/2025 6:56:00 AM
Last Saved By: lenovo
Total Editing Time: 346 Minutes
Last Printed On: 3/11/2025 6:57:00 AM
As of Last Complete Printing
Number of Pages: 76
Number of Words: 5,358 (approx.)
Number of Characters: 30,541 (approx.)