Assignment 2 : Control Structures and Loops
Reviewed by technical_saurabh
on
March 16, 2021
Rating:
team-analytics.blogspot.com
Reviewed by technical_saurabh
on
March 16, 2021
Rating: 5
Reviewed by technical_saurabh
on
March 16, 2021
Rating: 5

1) Give names to the elements in the list.
list_data <- ava="" br="" c="" ed="" lack="" list="" reen="" ython="">
print(list_data)
names(list_data) = c("Color", "Language(s)")
print("List with column names:")
print(list_data)
2) Add an element at the end of the list.
list_data <- ava="" br="" c="" ed="" lack="" list="" reen="" ython="">
print("List:")
print(list_data)
print("Add a new element at the end of the list:")
list_data[4] = "New element"
print("New list:")
print(list_data)
3) Remove the last element.
list_data <- ava="" br="" c="" ed="" lack="" list="" reen="" ython="">
print(list_data)
print("Remove the Last element of the list:")
list_data[2] = NULL
print("New list:")
print(list_data)
4) Update the 3rd Element
list_data <- br="" c="" ed="" lack="" list="" reen="" saurabh="" ython="">
print(list_data)
print("Update the second element of the list:")
list_data[3] = "R programming"
print("New list:")
print(list_data)
->->->->
m1 = matrix(c(1, 2, 3, 4, 5, 6), nrow = 2)
print("Matrix-1:")
print(m1)
m2 = matrix(c(0, 1, 2, 3, 0, 2), nrow = 2)
print("Matrix-2:")
print(m2)
result = m1 + m2
print("Result of addition")
print(result)
result = m1 - m2
print("Result of subtraction")
print(result)
num = as.integer(readline(prompt = "Enter a number: "))
for(i in 1:10) {
print(paste(num,'x', i, '=', num*i))
}
Reviewed by technical_saurabh
on
December 28, 2020
Rating: 5
Program 1 :
Answer :