Monday, December 11, 2023

Program 5- List and operators R Programming Lab - Bsc CS DA and BSC ML And AI -Bharathiar University -

 

B.Sc Computer Science  

R Programming - Lab  

Bharathiar University 

Program 5

List and Operators

Program 5- Write a R program to perform various operations on lists

SOURCE CODE:

# R program for lists

# Create a list 

rollno <- c(10,11,12)

name <- c("ram","rocky","raj")

marks <- c(98,99,80)

rank <- c('B','A','C')

student <- list(rollno, name, marks, rank)


# Print the original list

print("Original List:")

print(student)


# naming the original list

print("Original List with names:")

names(student) <- c("Roll number", "Name", "Marks", "Rank")

print(student)



# Accessing elements in the list

print("Accessing third element:")

print(student[3])  


# Accessing fourth element with name in the list

print("Accessing fourth element with name:")

print(student$Rank)  



# Adding an element to the list  

print("Adding an element:")

student[5] <- "Bsc IT"

print(student)


# updating an element to the list  

print("updating last element:")

student[5] <- "Bsc CS"

print(student)


# Calculating the length of the list

print("Length of the list:")

student_length <- length(student)

print(student_length)



# Removing an element from the list

print("Removing an element:")

student <- student[-5]  # Remove the fifth element

print(student)



Sample Output:

No comments:

Post a Comment

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...