![]() My.matrix<] } #save the vector, last element of the list, in a matrix ![]() <- my.function(par) #save the list from the function My.matrix<-matrix(nrow=12, ncol=4) #create a matrix You can achieve this result with this simple for cicle: That function (we’ll call it my.list) returns a list of three elements, and you want to save the last one, for example a vector of four elements. Now suppose that you have a function which is invoked multiple times. For example, if I want to extract the number 8 from my.list: my.list] We are creating a list with a matrix, a string and a vector: my.list <- list(matrix(nrow=5, ncol=2), "hello", c(10,8,7,3))īut this time, in order to access each element you need to use the double square brackets. The first solution is really similar to the use of cell arrays in Matlab. So, we are going to cover today three different solutions, based on different use of R lists.Ĭoncatenate different elements using lists There is, for example, the instruction ame(), but it forces you to have the same number of elements in each field. While this in Matlab is pretty easy with the instruction “cell(n.row, n.column)”, in R it can be more complex. ![]() If you are moving from Matlab to a R environment, probably you would like to keep using cell arrays to save different types of data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |