0

I have two data frames are 10 rows and 11 columns. I am trying to use the abind command from the abind package to stack the data frames into an array but it just rbinds them in the same demission. Is there any easer way to turn a data frame or a matrix into an array, or am I just missing one the arguments to get it to properly? Any help would be appreciated.

code looks like array <- abind(df1,df2)

Chuck
  • 13
  • 1
  • Welcome to StackOverflow. Please take a look at these tips on how to produce a [minimum, complete, and verifiable example](http://stackoverflow.com/help/mcve), as well as this post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – lmo Aug 24 '17 at 16:13
  • Maybe this will help: `abind(matrix(0, 4, 4), matrix(1, 4, 4), along=3)`. – lmo Aug 24 '17 at 16:43

1 Answers1

0

What you could easily do is this:

f <- function(dataframe1, dataframe2){
    m1 = data.matrix(dataframe1)
    m2 = data.matrix(dataframe2)

    vet = vector()
    for(i 1:( nrow(m1)*(ncol(m1)) )) { vet[i] = m1[i] }
    for(j 1:( nrow(m2)*(ncol(m2)) )) { vet[i+j] = m2[j] }

    return(vet)
}

Note:

-The i will retain its value, after the first loop ends

-Matrix and vector are the same thing, it just depends on you perception. What I'm doing is utilizing this fact. The a(2,2) element from a 2x2 matrix its the same as a(4) of a vector.

Homunculus
  • 329
  • 2
  • 12