For loop paired to t tests returning matrix error












1















I have a large set of data frames and would like to conduct a series of t-tests between different columns to find significance. Each data frame has identical headers but a different number of rows.



This is my code:



fileNames <- Sys.glob("*.txt")
for (fileName in fileNames) {
sample <- read.delim(fileName)
print(fileName)
placeholder.1 <- row_t_welch(sample[,c("A284_1", "A284_2")], sample[,c("A285_1", "A285_2")
}


Where fileNames = a list of: chr [1:383], and _1 & _2 are biological replicates





My code returns the error:



Error in assert_numeric_mat_or_vec(x):
"x" must be a numeric matrix or vector


If I type in the name of the files individually the code works but not when using 'sample'



Can anyone help me?
This is an excerpt from one of my files



      seq seq_id A284_1 A284_2 A285_1 A285_2 A286_1 A286_2 A287_1 A287_2 A288_1 A288_2 A289_1 A289_2 A290_1 A290_2 A291_1 A291_2   N2_1   N2_2
1 0.0345 0.0025 0.0134 0.0000 0.0114 0.0064 0.0011 0.0000 0.0000 0.0000 0.0000 0.0132 0.0094 0.0076 0.0000 0.0000 0.0023 0.0213 0.0130 0.0101
2 0.0394 0.0049 0.0015 0.0000 0.0011 0.0010 0.0000 0.0000 0.0015 0.0022 0.0013 0.0014 0.0011 0.0009 0.0000 0.0000 0.0021 0.0014 0.0013 0.0007
3 0.0296 0.0074 0.0000 0.0000 0.0008 0.0005 0.0011 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0038 0.0000 0.0000 0.0003 0.0014 0.0050 0.0032
4 0.0197 0.0099 0.0059 0.0015 0.0030 0.0044 0.0011 0.0075 0.0015 0.0022 0.0017 0.0023 0.0022 0.0023 0.0000 0.0054 0.0027 0.0014 0.0022 0.0022
5 0.0099 0.0123 0.0045 0.0046 0.0038 0.0049 0.0076 0.0000 0.0030 0.0067 0.0039 0.0054 0.0039 0.0067 0.0051 0.0054 0.0071 0.0071 0.0060 0.0052









share|improve this question

























  • read.delim() returns a data.frame whereas you require a matrix. Try converting it to a matrix.

    – anotherfred
    Jan 2 at 23:57











  • Please don't include images of your data. Include the output from dput(head(data)) or a simple made-up example that we can copy/paste into R

    – RAB
    Jan 3 at 1:13











  • Thankyou @anotherfred! It now works. What I did was insert sample <- data.matrix(sample) under sample <- read.delim(fileName) and print(placeholder.1) underneath my statistical test. This was as calling the placeholder.1 variable returned a null result

    – A. Palmer
    Jan 3 at 1:45


















1















I have a large set of data frames and would like to conduct a series of t-tests between different columns to find significance. Each data frame has identical headers but a different number of rows.



This is my code:



fileNames <- Sys.glob("*.txt")
for (fileName in fileNames) {
sample <- read.delim(fileName)
print(fileName)
placeholder.1 <- row_t_welch(sample[,c("A284_1", "A284_2")], sample[,c("A285_1", "A285_2")
}


Where fileNames = a list of: chr [1:383], and _1 & _2 are biological replicates





My code returns the error:



Error in assert_numeric_mat_or_vec(x):
"x" must be a numeric matrix or vector


If I type in the name of the files individually the code works but not when using 'sample'



Can anyone help me?
This is an excerpt from one of my files



      seq seq_id A284_1 A284_2 A285_1 A285_2 A286_1 A286_2 A287_1 A287_2 A288_1 A288_2 A289_1 A289_2 A290_1 A290_2 A291_1 A291_2   N2_1   N2_2
1 0.0345 0.0025 0.0134 0.0000 0.0114 0.0064 0.0011 0.0000 0.0000 0.0000 0.0000 0.0132 0.0094 0.0076 0.0000 0.0000 0.0023 0.0213 0.0130 0.0101
2 0.0394 0.0049 0.0015 0.0000 0.0011 0.0010 0.0000 0.0000 0.0015 0.0022 0.0013 0.0014 0.0011 0.0009 0.0000 0.0000 0.0021 0.0014 0.0013 0.0007
3 0.0296 0.0074 0.0000 0.0000 0.0008 0.0005 0.0011 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0038 0.0000 0.0000 0.0003 0.0014 0.0050 0.0032
4 0.0197 0.0099 0.0059 0.0015 0.0030 0.0044 0.0011 0.0075 0.0015 0.0022 0.0017 0.0023 0.0022 0.0023 0.0000 0.0054 0.0027 0.0014 0.0022 0.0022
5 0.0099 0.0123 0.0045 0.0046 0.0038 0.0049 0.0076 0.0000 0.0030 0.0067 0.0039 0.0054 0.0039 0.0067 0.0051 0.0054 0.0071 0.0071 0.0060 0.0052









share|improve this question

























  • read.delim() returns a data.frame whereas you require a matrix. Try converting it to a matrix.

    – anotherfred
    Jan 2 at 23:57











  • Please don't include images of your data. Include the output from dput(head(data)) or a simple made-up example that we can copy/paste into R

    – RAB
    Jan 3 at 1:13











  • Thankyou @anotherfred! It now works. What I did was insert sample <- data.matrix(sample) under sample <- read.delim(fileName) and print(placeholder.1) underneath my statistical test. This was as calling the placeholder.1 variable returned a null result

    – A. Palmer
    Jan 3 at 1:45
















1












1








1








I have a large set of data frames and would like to conduct a series of t-tests between different columns to find significance. Each data frame has identical headers but a different number of rows.



This is my code:



fileNames <- Sys.glob("*.txt")
for (fileName in fileNames) {
sample <- read.delim(fileName)
print(fileName)
placeholder.1 <- row_t_welch(sample[,c("A284_1", "A284_2")], sample[,c("A285_1", "A285_2")
}


Where fileNames = a list of: chr [1:383], and _1 & _2 are biological replicates





My code returns the error:



Error in assert_numeric_mat_or_vec(x):
"x" must be a numeric matrix or vector


If I type in the name of the files individually the code works but not when using 'sample'



Can anyone help me?
This is an excerpt from one of my files



      seq seq_id A284_1 A284_2 A285_1 A285_2 A286_1 A286_2 A287_1 A287_2 A288_1 A288_2 A289_1 A289_2 A290_1 A290_2 A291_1 A291_2   N2_1   N2_2
1 0.0345 0.0025 0.0134 0.0000 0.0114 0.0064 0.0011 0.0000 0.0000 0.0000 0.0000 0.0132 0.0094 0.0076 0.0000 0.0000 0.0023 0.0213 0.0130 0.0101
2 0.0394 0.0049 0.0015 0.0000 0.0011 0.0010 0.0000 0.0000 0.0015 0.0022 0.0013 0.0014 0.0011 0.0009 0.0000 0.0000 0.0021 0.0014 0.0013 0.0007
3 0.0296 0.0074 0.0000 0.0000 0.0008 0.0005 0.0011 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0038 0.0000 0.0000 0.0003 0.0014 0.0050 0.0032
4 0.0197 0.0099 0.0059 0.0015 0.0030 0.0044 0.0011 0.0075 0.0015 0.0022 0.0017 0.0023 0.0022 0.0023 0.0000 0.0054 0.0027 0.0014 0.0022 0.0022
5 0.0099 0.0123 0.0045 0.0046 0.0038 0.0049 0.0076 0.0000 0.0030 0.0067 0.0039 0.0054 0.0039 0.0067 0.0051 0.0054 0.0071 0.0071 0.0060 0.0052









share|improve this question
















I have a large set of data frames and would like to conduct a series of t-tests between different columns to find significance. Each data frame has identical headers but a different number of rows.



This is my code:



fileNames <- Sys.glob("*.txt")
for (fileName in fileNames) {
sample <- read.delim(fileName)
print(fileName)
placeholder.1 <- row_t_welch(sample[,c("A284_1", "A284_2")], sample[,c("A285_1", "A285_2")
}


Where fileNames = a list of: chr [1:383], and _1 & _2 are biological replicates





My code returns the error:



Error in assert_numeric_mat_or_vec(x):
"x" must be a numeric matrix or vector


If I type in the name of the files individually the code works but not when using 'sample'



Can anyone help me?
This is an excerpt from one of my files



      seq seq_id A284_1 A284_2 A285_1 A285_2 A286_1 A286_2 A287_1 A287_2 A288_1 A288_2 A289_1 A289_2 A290_1 A290_2 A291_1 A291_2   N2_1   N2_2
1 0.0345 0.0025 0.0134 0.0000 0.0114 0.0064 0.0011 0.0000 0.0000 0.0000 0.0000 0.0132 0.0094 0.0076 0.0000 0.0000 0.0023 0.0213 0.0130 0.0101
2 0.0394 0.0049 0.0015 0.0000 0.0011 0.0010 0.0000 0.0000 0.0015 0.0022 0.0013 0.0014 0.0011 0.0009 0.0000 0.0000 0.0021 0.0014 0.0013 0.0007
3 0.0296 0.0074 0.0000 0.0000 0.0008 0.0005 0.0011 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0038 0.0000 0.0000 0.0003 0.0014 0.0050 0.0032
4 0.0197 0.0099 0.0059 0.0015 0.0030 0.0044 0.0011 0.0075 0.0015 0.0022 0.0017 0.0023 0.0022 0.0023 0.0000 0.0054 0.0027 0.0014 0.0022 0.0022
5 0.0099 0.0123 0.0045 0.0046 0.0038 0.0049 0.0076 0.0000 0.0030 0.0067 0.0039 0.0054 0.0039 0.0067 0.0051 0.0054 0.0071 0.0071 0.0060 0.0052






r matrix vector t-test






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 2:00







A. Palmer

















asked Jan 2 at 23:50









A. PalmerA. Palmer

93




93













  • read.delim() returns a data.frame whereas you require a matrix. Try converting it to a matrix.

    – anotherfred
    Jan 2 at 23:57











  • Please don't include images of your data. Include the output from dput(head(data)) or a simple made-up example that we can copy/paste into R

    – RAB
    Jan 3 at 1:13











  • Thankyou @anotherfred! It now works. What I did was insert sample <- data.matrix(sample) under sample <- read.delim(fileName) and print(placeholder.1) underneath my statistical test. This was as calling the placeholder.1 variable returned a null result

    – A. Palmer
    Jan 3 at 1:45





















  • read.delim() returns a data.frame whereas you require a matrix. Try converting it to a matrix.

    – anotherfred
    Jan 2 at 23:57











  • Please don't include images of your data. Include the output from dput(head(data)) or a simple made-up example that we can copy/paste into R

    – RAB
    Jan 3 at 1:13











  • Thankyou @anotherfred! It now works. What I did was insert sample <- data.matrix(sample) under sample <- read.delim(fileName) and print(placeholder.1) underneath my statistical test. This was as calling the placeholder.1 variable returned a null result

    – A. Palmer
    Jan 3 at 1:45



















read.delim() returns a data.frame whereas you require a matrix. Try converting it to a matrix.

– anotherfred
Jan 2 at 23:57





read.delim() returns a data.frame whereas you require a matrix. Try converting it to a matrix.

– anotherfred
Jan 2 at 23:57













Please don't include images of your data. Include the output from dput(head(data)) or a simple made-up example that we can copy/paste into R

– RAB
Jan 3 at 1:13





Please don't include images of your data. Include the output from dput(head(data)) or a simple made-up example that we can copy/paste into R

– RAB
Jan 3 at 1:13













Thankyou @anotherfred! It now works. What I did was insert sample <- data.matrix(sample) under sample <- read.delim(fileName) and print(placeholder.1) underneath my statistical test. This was as calling the placeholder.1 variable returned a null result

– A. Palmer
Jan 3 at 1:45







Thankyou @anotherfred! It now works. What I did was insert sample <- data.matrix(sample) under sample <- read.delim(fileName) and print(placeholder.1) underneath my statistical test. This was as calling the placeholder.1 variable returned a null result

– A. Palmer
Jan 3 at 1:45














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%2f54014676%2ffor-loop-paired-to-t-tests-returning-matrix-error%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%2f54014676%2ffor-loop-paired-to-t-tests-returning-matrix-error%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

Angular Downloading a file using contenturl with Basic Authentication

Monofisismo

Olmecas