You can add additional columns to a matrix that consists of lists in several ways. Here are two examples:
my_matrix <- matrix(list(list1=c(1,2,3), list2=c("a","b","c")), nrow=3)
To add an additional column to "my_matrix" consisting of a new list "list3", you can use the cbind() function as follows:
new_list <- list("d", "e", "f")
my_matrix <- cbind(my_matrix, new_list)
This will add the new list "newlist" as a new column to the matrix "mymatrix".
my_matrix <- matrix(list(list1=c(1,2,3), list2=c("a","b","c")), nrow=3)
To add an additional column to "my_matrix" consisting of a new list "list3", you can use matrix indexing as follows:
new_list <- list("d", "e", "f")
my_matrix <- cbind(my_matrix, list())
my_matrix[,3] <- new_list
This will add a new, empty column to "mymatrix" using cbind() function first, and then populate the column with the new list "newlist" using matrix indexing.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-01-23 11:00:00 +0000
Seen: 13 times
Last updated: Jan 17 '22
How can one generate a list by using a portion of another list?
How can Swagger V3 use Schema Annotation to transform a List of Long to look like a List of String?
How can I modify the width of the column filter in an R shiny datatable?
How can dote be eliminated from the menu items in HTML?
How can an EditForm validate a list object in MudBlazor?
How do you update a dataframe within a for loop in R after passing a list?
How can resetting a list be avoided during a loop?
What is the LINQ query to retrieve the employee with the second highest salary?