0% found this document useful (0 votes)
5 views21 pages

ITW Project File

Uploaded by

hbdz936
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views21 pages

ITW Project File

Uploaded by

hbdz936
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

INDIRA GANDHI DELHI TECHNICAL UNIVERSITY

KASHMERE GATE, NEW DELHI-110006

IT WORKSHOP(BAI-102)
(2024-2028)

SUBMITTED BY: SUBMITTED TO:


HARSHITA BHARDWAJ MS.
IT1 NISHA
04401032024 MA’AM
INDEX

S.No EXPERIMENT

1. Program To Introduction To R Language

2. Program To Implement Basic Functionality of R

3. Program To Implement Concept Of Data Frame

4. Program To perform computation on matrices in R

5. Program To Implement Control Statements in R

6. Program To Implement data import and export

7. Program To apply advanced data visualization techniques to analyze data

8. Program To apply functions and Packages

9. Program To Apply Data and Preprocessing


EXPERIMENT 1
(PROGRAM TO INTRODUCTION OF R LANGUAGE)

CODE:
1. Printing A Statement in R

>print(“Hello World”)

2.Performing Basic Arithematic Operations In R


>sum = 6+4
>subtract = 6-4
>multiply = 6*4
>division = 6%/%4
EXPERIMENT 2
(PROGRAM TO IMPLEMENT BASIC FUNCTIONALITY
IN R LANGUAGE)

CODE:
1. DECLARING TWO VECTORS V1 AND V2

v1<-c(10,20,30)

v2<-c(40,50,60)

2. Performing Arithmetic Operations on Vectors

sum<-v1+v2

difference<-v2-v1

multiply<-v1*v2

division<-v1/v2

OUTPUT:
EXPERIMENT 3
(PROGRAM TO IMPLEMENT CONCEPT OF DATA
FRAMES IN R LANGUAGE)

CODE:
~CREATING A DATA FRAME IN R

df<-data.frame(

Name=c("John","Alice","Belle"),

Age=c(18,15,16),

Rollno=c(10,3,6)

print(df)

OUTPUT:
~Structure Of Data Frame:

df<-data.frame(

Name=c("John","Alice","Belle"),

Age=c(18,15,16),

Rollno=c(10,3,6)

print(str(df))

OUTPUT:

~Summary Of Data Frame

df<-data.frame(

Name=c("John","Alice","Belle"),

Age=c(18,15,16),

Rollno=c(10,3,6)

print(summary(df))

OUTPUT:
~Extracting Data From DataFrame

df<-data.frame(

Name=c("John","Alice","Belle"),

Age=c(18,15,16),

Rollno=c(10,3,6)

result<-df$Name

print(result)

OUTPUT:
EXPERIMENT 4
(PROGRAM TO PERFORM CALCULATIONS ON
MATRICES IN R )

CODE:
1.Declaring matrices m1 and m2:

m1<-matrix(c(1,2,3,4,5,6),nrow=2)

print(m1)

m2<-matrix(c(7,8,9,10,11,12),nrow=2)

print(m2)

OUTPUT:

2. Performing Arithmetic Operations on Matrices

m1<-matrix(c(1,2,3,4,5,6),nrow=2)

m2<-matrix(c(7,8,9,10,11,12),nrow=2)
added_matrix <- m1+m2

print(added_matrix)

OUTPUT:

subtracted_matrix <- m2-m1

print(subtracted_matrix)

multiplied_matrix <- m2*m1

print(multiplied_matrix)

divided_matrix <- m2/m1

print(divided_matrix)

3. Accessing elements of a matrix

print(m1[1,3]) #FIRST ROW THIRD COLUMN ELEMENT OF m1 matrix

print(m2[2,3]) #SECOND ROW THIRD COLUMN ELEMENT OF m2 matrix


4.Modifying elements of a matrix

m1<-matrix(c(1,2,3,4,5,6),nrow=2)

m2<-matrix(c(7,8,9,10,11,12),nrow=2)

m1[1,3] = 13

print(m1)
EXPERIMENT 5
(PROGRAM TO IMPLEMENT CONTROL STATEMENTS
IN R )

CODE:
1. If condition

x<-5

If (x>3){

print (“x is greater than 3”)

OUTPUT:

2. If-elif-else condition

x<-5

if (x>7){

print("x is greater than 7")

}else if (x==5){

print("x is equal to 5")

}else{
print("x is less than 5")

3. For Loop

for(i in 1:10){

print(i)

4. While Loop

x<-1

while(x<=5){

print(x)

x<-x+1

}
EXPERIMENT 6
(PROGRAM TO IMPLEMENT DATA IMPORT AND
EXPORT IN R)

CODE:
1. IMPORTING AND EXPORTING DATA IN A CSV FILE

employee_data <- data.frame(

employee_code = c(101, 102, 103),

employee_name = c("Alice", "Bob", "Charlie"),

salary = c(50000, 55000, 60000) )

write.csv(employee_data, "employee_data.csv", row.names = FALSE)

read.csv(employee_data, "employee_data.csv", row.names = FALSE)

OUTPUT:
EXPERIMENT 7
(PROGRAM TO APPLY DATA VISUALIZATION
TECHNIQUES TO ANALYZE DATA)

CODE:
1.THREE DIMENSIONAL STRUCTURE

x <- seq(-10, 10, length.out = 30)

y <- seq(-10, 10, length.out = 30)

z <- outer(x, y, function(x, y) sin(sqrt(x^2 + y^2)))

persp(x, y, z, col = "lightblue", theta = 30, phi = 30)

OUTPUT:
2. PLOTTING DISTRIBUTIONS

#HISTOGRAM

hist(mtcars$mpg, breaks = 10, col = "light green", xlab = "Miles per Gallon", main
= "Distribution of MPG")

OUTPUT:
#BOX PLOT

boxplot(mpg ~ cyl, data = mtcars, col = c("orange", "yellow", "green"), main = "MPG by Cylinder
Count")
#BUBBLE PLOT

plot(mtcars$wt, mtcars$mpg, xlim = c(1, 6), ylim = c(10, 35), xlab = "Weight", ylab = "MPG")
EXPERIMENT 8
(PROGRAM TO APPLY FUNCTIONS AND PACKAGES)

CODE(applying package(ggplot2)):
library(ggplot2)

ggplot(mtcars, aes(factor(cyl), mpg)) +

geom_violin(fill = "lightblue") +

labs(x = "Cylinders", y = "MPG")

OUTPUT:

CODE(applying function(apply)):
my_matrix <- matrix(1:12, nrow = 4, ncol = 3)
print("Original Matrix:")

print(my_matrix)

row_sums <- apply(my_matrix, 1, sum)

print("Sum of rows:")

print(row_sums)

col_means <- apply(my_matrix, 2, mean)

print("Mean of columns:")

print(col_means)

OUTPUT:

EXPERIMENT 9
(PROGRAM TO APPLY DATA CLEANING AND
PREPROCESSING)

CODE:
# Load a sample dataset

data <- data.frame(

Name = c("Alice", "Bob", "Charlie", NA, "Eve"),

Age = c(25, NA, 30, 35, 40),

Salary = c(50000, 60000, NA, 55000, 65000),

Gender = c("F", "M", NA, "M", "F")

# Remove rows with missing values

cleaned_data <- na.omit(data)

# Fill missing 'Age' with mean

data$Age[is.na(data$Age)] <- mean(data$Age, na.rm = TRUE)

# Replace missing 'Gender' with mode

mode_gender <- names(which.max(table(data$Gender)))

data$Gender[is.na(data$Gender)] <- mode_gender

# Normalize 'Salary'

data$Salary <- (data$Salary - min(data$Salary, na.rm = TRUE)) /


(max(data$Salary, na.rm = TRUE) - min(data$Salary, na.rm = TRUE))

# Print cleaned data

print(cleaned_data)

print(data)

OUTPUT:
CLEANED AND PREPROCESSED DATA:

You might also like