Write a R program to list containing a vector, a matrix and a list and give names to the elements in the list.
list_data <- list(c("Red","Green","Black"), matrix(c(1,3,5,7,9,11), nrow = 2), list("Python", "PHP", "Java")) print("List:") print(list_data) names(list_data) = c("Color", "Odd numbers", "Language(s)") print("List with column names:") 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" [[3]][[2]] [1] "PHP" [[3]][[3]] [1] "Java" [1] "List with column names:" $Color [1] "Red" "Green" "Black" $`Odd numbers` [,1] [,2] [,3] [1,] 1 5 9 [2,] 3 7 11 $`Language(s)` $`Language(s)`[[1]] [1] "Python" $`Language(s)`[[2]] [1] "PHP" $`Language(s)`[[3]] [1] "Java"
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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" [[3]][[2]] [1] "PHP" [[3]][[3]] [1] "Java" [1] "List with column names:" $Color [1] "Red" "Green" "Black" $`Odd numbers` [,1] [,2] [,3] [1,] 1 5 9 [2,] 3 7 11 $`Language(s)` $`Language(s)`[[1]] [1] "Python" $`Language(s)`[[2]] [1] "PHP" $`Language(s)`[[3]] [1] "Java"need an explanation for this answer? contact us directly to get an explanation for this answer