This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
15.List.r
114 lines (104 loc) · 2.03 KB
/
15.List.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Aim: Write a R program to create a list and modify its components
# Procedure:
# Create a list containing roll number-170981A0201, student name-Md.Ahmed, gender-Male
# and number of backlogs-2 for a student and do the following.
# (i) Give names to the components 0f the list
# ii) Add a component with name passport_no. at the end of the list
# iii) Remove the third component
# iv) update the number of backlogs to 1
# Source code:
stu_list <- function()
{
student=list("170981A0201","Md.Ahmed","Male",2)
# Print the list
cat("The student details are \n")
print(student)
# (i) Give names to the components of the list
names(student)=c("Roll_no.","Name","Gender","Backlogs")
# Print the list with names
cat("The list with component names \n")
print(student)
# ii) Add a component with name passport_no. at the end of the list
student$passport_no.="M7802031"
cat("The list with passport number \n")
print(student)
# iii) Remove the third component
student$Gender=NULL
cat("The list after removing gender\n")
print(student)
# iv) update the number of backlogs to 1
student$Backlogs=1
cat("The updated backlogs is \n")
print(student)
}
stu_list()
# OUTPUTS:-
# -------
#
# The student details are
# [[1]]
# [1] "170981A0201"
#
# [[2]]
# [1] "Md.Ahmed"
#
# [[3]]
# [1] "Male"
#
# [[4]]
# [1] 2
#
# The list with component names
# $Roll_no.
# [1] "170981A0201"
#
# $Name
# [1] "Md.Ahmed"
#
# $Gender
# [1] "Male"
#
# $Backlogs
# [1] 2
#
# The list with passport number
# $Roll_no.
# [1] "170981A0201"
#
# $Name
# [1] "Md.Ahmed"
#
# $Gender
# [1] "Male"
#
# $Backlogs
# [1] 2
#
# $passport_no.
# [1] "M7802031"
#
# The list after removing gender
# $Roll_no.
# [1] "170981A0201"
#
# $Name
# [1] "Md.Ahmed"
#
# $Backlogs
# [1] 2
#
# $passport_no.
# [1] "M7802031"
#
# The updated backlogs is
# $Roll_no.
# [1] "170981A0201"
#
# $Name
# [1] "Md.Ahmed"
#
# $Backlogs
# [1] 1
#
# $passport_no.
# [1] "M7802031"