Sergey D.
Sergey D.

Reputation: 3

Set range data frame in R

I have a large number (17000) of 96x97 matrices with names b1,b2...b17000. I need to combine them into an array 96x97x17000. I am trying to do this through an array function:

s=array(b1,b2...b17000,dim=c(96,97,17000))

The problem is that for this function to work, you need to write down the name of all the matrices. How can this be done without writing down the name of the matrices 17,000 times?

I tried to set this as a range b1:b17000 but it does not work correctly.

Upvotes: 0

Views: 98

Answers (1)

Joshua Mire
Joshua Mire

Reputation: 736

Based on your original question the below code should work for you.

names<-c(paste0("b",1:17000))
s<-array(unlist(mget(names)),dim=c(96,97,17000))

This will create a vector called names containing your the names of your matrices (assuming they're actually called m1, m2,... m17000). For example: names[1] will be b1 and names[2] will be b2, so on and so forth.

You can then use names to reference your matrices array as shown in my suggested code.

I hope this helps!

Upvotes: 1

Related Questions