Write a R program to create a list containing a vector, a matrix and a list and update the last element

  • برمجة R

Write a R program to create a list containing a vector, a matrix and a list and update the last element.

الأجوبة

list_data <- list(c("Red","Green","Black"), matrix(c(1,3,5,7,9,11), nrow = 2),
list("Python"))
print("List:")
print(list_data)
print("Update the second element of the list:")
list_data[3] =  "R programming"
print("New list:")
print(list_data)

Sample Output:

[1] "List:"
[[1]]
[1] "Red"   "Green" "Black"

[[2]]
     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    3    7   11

[[3]]
[[3]][[1]]
[1] "Python"


[1] "Update the second element of the list:"
[1] "New list:"
[[1]]
[1] "Red"   "Green" "Black"

[[2]]
     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    3    7   11

[[3]]
[1] "R programming"
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...