Data frames as the third dimension in a 3D matrix in R












0















How can I create a 3D array with multiple data frames (or, I can convert them to arrays if that makes more sense) as the third dimension? So, I have multiple data frames that have rows and columns (are 2D), and I want them in one 3D array. The columns are the same across all data frames, but the number of rows is variable.



a <- c(1, 2)
b <- c(2, 1)
df <- data.frame(a, b)

c <- c(3, 4)
d <- c(4, 3)
df2 <- data.frame(c, d)


I need df and df2 to be the third dimension in an array










share|improve this question




















  • 1





    Do you just mean a list? list(df1, df2, df3) ? If so, that was the exact output I suggested in my answer to your previous question.

    – thelatemail
    Nov 22 '18 at 0:34








  • 1





    Something like this - stackoverflow.com/a/36440267/496803 - in particular simplify2array(list(x1, x2, x3)) where x1/2/3 are matrices all of the same size.

    – thelatemail
    Nov 22 '18 at 0:53






  • 1





    stackoverflow.com/questions/4310727/…

    – Chris
    Nov 22 '18 at 0:56






  • 1





    As per the previous answer at the linked question - simplify2array(lapply(list(df,df2),as.matrix)) works.

    – thelatemail
    Nov 22 '18 at 1:04






  • 1





    Using exactly what you have above in the question and your code to create and subset test, I get 1 - the first column of the first row in the first strata. Maybe try with a fresh R session.

    – thelatemail
    Nov 22 '18 at 1:10
















0















How can I create a 3D array with multiple data frames (or, I can convert them to arrays if that makes more sense) as the third dimension? So, I have multiple data frames that have rows and columns (are 2D), and I want them in one 3D array. The columns are the same across all data frames, but the number of rows is variable.



a <- c(1, 2)
b <- c(2, 1)
df <- data.frame(a, b)

c <- c(3, 4)
d <- c(4, 3)
df2 <- data.frame(c, d)


I need df and df2 to be the third dimension in an array










share|improve this question




















  • 1





    Do you just mean a list? list(df1, df2, df3) ? If so, that was the exact output I suggested in my answer to your previous question.

    – thelatemail
    Nov 22 '18 at 0:34








  • 1





    Something like this - stackoverflow.com/a/36440267/496803 - in particular simplify2array(list(x1, x2, x3)) where x1/2/3 are matrices all of the same size.

    – thelatemail
    Nov 22 '18 at 0:53






  • 1





    stackoverflow.com/questions/4310727/…

    – Chris
    Nov 22 '18 at 0:56






  • 1





    As per the previous answer at the linked question - simplify2array(lapply(list(df,df2),as.matrix)) works.

    – thelatemail
    Nov 22 '18 at 1:04






  • 1





    Using exactly what you have above in the question and your code to create and subset test, I get 1 - the first column of the first row in the first strata. Maybe try with a fresh R session.

    – thelatemail
    Nov 22 '18 at 1:10














0












0








0








How can I create a 3D array with multiple data frames (or, I can convert them to arrays if that makes more sense) as the third dimension? So, I have multiple data frames that have rows and columns (are 2D), and I want them in one 3D array. The columns are the same across all data frames, but the number of rows is variable.



a <- c(1, 2)
b <- c(2, 1)
df <- data.frame(a, b)

c <- c(3, 4)
d <- c(4, 3)
df2 <- data.frame(c, d)


I need df and df2 to be the third dimension in an array










share|improve this question
















How can I create a 3D array with multiple data frames (or, I can convert them to arrays if that makes more sense) as the third dimension? So, I have multiple data frames that have rows and columns (are 2D), and I want them in one 3D array. The columns are the same across all data frames, but the number of rows is variable.



a <- c(1, 2)
b <- c(2, 1)
df <- data.frame(a, b)

c <- c(3, 4)
d <- c(4, 3)
df2 <- data.frame(c, d)


I need df and df2 to be the third dimension in an array







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 0:57







Lisa

















asked Nov 22 '18 at 0:15









LisaLisa

3741218




3741218








  • 1





    Do you just mean a list? list(df1, df2, df3) ? If so, that was the exact output I suggested in my answer to your previous question.

    – thelatemail
    Nov 22 '18 at 0:34








  • 1





    Something like this - stackoverflow.com/a/36440267/496803 - in particular simplify2array(list(x1, x2, x3)) where x1/2/3 are matrices all of the same size.

    – thelatemail
    Nov 22 '18 at 0:53






  • 1





    stackoverflow.com/questions/4310727/…

    – Chris
    Nov 22 '18 at 0:56






  • 1





    As per the previous answer at the linked question - simplify2array(lapply(list(df,df2),as.matrix)) works.

    – thelatemail
    Nov 22 '18 at 1:04






  • 1





    Using exactly what you have above in the question and your code to create and subset test, I get 1 - the first column of the first row in the first strata. Maybe try with a fresh R session.

    – thelatemail
    Nov 22 '18 at 1:10














  • 1





    Do you just mean a list? list(df1, df2, df3) ? If so, that was the exact output I suggested in my answer to your previous question.

    – thelatemail
    Nov 22 '18 at 0:34








  • 1





    Something like this - stackoverflow.com/a/36440267/496803 - in particular simplify2array(list(x1, x2, x3)) where x1/2/3 are matrices all of the same size.

    – thelatemail
    Nov 22 '18 at 0:53






  • 1





    stackoverflow.com/questions/4310727/…

    – Chris
    Nov 22 '18 at 0:56






  • 1





    As per the previous answer at the linked question - simplify2array(lapply(list(df,df2),as.matrix)) works.

    – thelatemail
    Nov 22 '18 at 1:04






  • 1





    Using exactly what you have above in the question and your code to create and subset test, I get 1 - the first column of the first row in the first strata. Maybe try with a fresh R session.

    – thelatemail
    Nov 22 '18 at 1:10








1




1





Do you just mean a list? list(df1, df2, df3) ? If so, that was the exact output I suggested in my answer to your previous question.

– thelatemail
Nov 22 '18 at 0:34







Do you just mean a list? list(df1, df2, df3) ? If so, that was the exact output I suggested in my answer to your previous question.

– thelatemail
Nov 22 '18 at 0:34






1




1





Something like this - stackoverflow.com/a/36440267/496803 - in particular simplify2array(list(x1, x2, x3)) where x1/2/3 are matrices all of the same size.

– thelatemail
Nov 22 '18 at 0:53





Something like this - stackoverflow.com/a/36440267/496803 - in particular simplify2array(list(x1, x2, x3)) where x1/2/3 are matrices all of the same size.

– thelatemail
Nov 22 '18 at 0:53




1




1





stackoverflow.com/questions/4310727/…

– Chris
Nov 22 '18 at 0:56





stackoverflow.com/questions/4310727/…

– Chris
Nov 22 '18 at 0:56




1




1





As per the previous answer at the linked question - simplify2array(lapply(list(df,df2),as.matrix)) works.

– thelatemail
Nov 22 '18 at 1:04





As per the previous answer at the linked question - simplify2array(lapply(list(df,df2),as.matrix)) works.

– thelatemail
Nov 22 '18 at 1:04




1




1





Using exactly what you have above in the question and your code to create and subset test, I get 1 - the first column of the first row in the first strata. Maybe try with a fresh R session.

– thelatemail
Nov 22 '18 at 1:10





Using exactly what you have above in the question and your code to create and subset test, I get 1 - the first column of the first row in the first strata. Maybe try with a fresh R session.

– thelatemail
Nov 22 '18 at 1:10












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422219%2fdata-frames-as-the-third-dimension-in-a-3d-matrix-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422219%2fdata-frames-as-the-third-dimension-in-a-3d-matrix-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'