Enter Matrices in R

1

I want to enter a% n of matrices in R in a function, for example:

Matriz<- as.integer(readline(prompt="CUantas Matrices desea? "))

for(i in 1:Matriz){

  Fila = as.integer(readline(prompt="Ingrese el tamaño de la fila: "))

Columna = as.integer(readline(prompt="Ingrese el tamaño de la Columna: "))

 AA<- matrix(data = sample(-10:10, Fila*Columna, replace = FALSE), nrow = Fila, ncol = Columna)

}

where you enter the matrices that you want, but you keep them in variable AA and I need you to store them in different variables, how can I get this?

    
asked by jose 21.10.2017 в 19:29
source

1 answer

0

The first is to work with a single list and assign each matrix to an index of this list.

Something like this:

lista <- list()
for(i in 1:5){
    lista[i]<-i # Acá asignamos la matriz
}

> lista[[1]]
[1] 1

The other way is to create variables dynamically using assign()

variables <- c("a", "b", "c", "d", "e")
for(i in 1:5){
    assign(variables[i], i) # Acá asignamos la matriz
}
> a
[1] 1
    
answered by 23.10.2017 / 04:45
source