Slip 10 - E) Write a script in R to create a list of cities and perform the following 1) Give names to the elements in the list. 2) Add an element at the end of the list. 3) Remove the last element. 4) Update the 3rd Element

Solution:

list_data <- list("Pune","Nasik","Mumbai")
print(list_data)

names(list_data)<-c("Edu City","Grape City","Capital")
print(list_data)

list_data[4]<-"New element"
print(list_data)

list_data[4] <- NULL
print(list_data)

list_data[3] <- "updated element"
print(list_data[3])

Post a Comment

0 Comments