How to create external folder in a loop in R?












0















Ok, actually I have a loop of 50 iterations and then I need an output file for each of these iterations. That happens is that with my current code I only obtain the output file corresponding to the last iteration, so could you give me a code to let me get all the files in mi current folder??. Thank you enter image description here



part is a vector of length 50 (really a list but it does not matter










share|improve this question


















  • 1





    Welcome to SO. Your question is not a good one and is likely to bring in some downvotes if not edited: stackoverflow.com/help/how-to-ask

    – sindri_baldur
    Nov 15 '18 at 9:47








  • 1





    write.table(part[[i]], paste0(i, ".txt") Or maybe sprintf("%02d.txt", i) instead of paste0.

    – Rui Barradas
    Nov 15 '18 at 9:52













  • This actually works!!. I´m a rookie in regards to R. Thank you!!!

    – Angel Lopez Oriona
    Nov 15 '18 at 10:00
















0















Ok, actually I have a loop of 50 iterations and then I need an output file for each of these iterations. That happens is that with my current code I only obtain the output file corresponding to the last iteration, so could you give me a code to let me get all the files in mi current folder??. Thank you enter image description here



part is a vector of length 50 (really a list but it does not matter










share|improve this question


















  • 1





    Welcome to SO. Your question is not a good one and is likely to bring in some downvotes if not edited: stackoverflow.com/help/how-to-ask

    – sindri_baldur
    Nov 15 '18 at 9:47








  • 1





    write.table(part[[i]], paste0(i, ".txt") Or maybe sprintf("%02d.txt", i) instead of paste0.

    – Rui Barradas
    Nov 15 '18 at 9:52













  • This actually works!!. I´m a rookie in regards to R. Thank you!!!

    – Angel Lopez Oriona
    Nov 15 '18 at 10:00














0












0








0








Ok, actually I have a loop of 50 iterations and then I need an output file for each of these iterations. That happens is that with my current code I only obtain the output file corresponding to the last iteration, so could you give me a code to let me get all the files in mi current folder??. Thank you enter image description here



part is a vector of length 50 (really a list but it does not matter










share|improve this question














Ok, actually I have a loop of 50 iterations and then I need an output file for each of these iterations. That happens is that with my current code I only obtain the output file corresponding to the last iteration, so could you give me a code to let me get all the files in mi current folder??. Thank you enter image description here



part is a vector of length 50 (really a list but it does not matter







r






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 9:44









Angel Lopez OrionaAngel Lopez Oriona

1




1








  • 1





    Welcome to SO. Your question is not a good one and is likely to bring in some downvotes if not edited: stackoverflow.com/help/how-to-ask

    – sindri_baldur
    Nov 15 '18 at 9:47








  • 1





    write.table(part[[i]], paste0(i, ".txt") Or maybe sprintf("%02d.txt", i) instead of paste0.

    – Rui Barradas
    Nov 15 '18 at 9:52













  • This actually works!!. I´m a rookie in regards to R. Thank you!!!

    – Angel Lopez Oriona
    Nov 15 '18 at 10:00














  • 1





    Welcome to SO. Your question is not a good one and is likely to bring in some downvotes if not edited: stackoverflow.com/help/how-to-ask

    – sindri_baldur
    Nov 15 '18 at 9:47








  • 1





    write.table(part[[i]], paste0(i, ".txt") Or maybe sprintf("%02d.txt", i) instead of paste0.

    – Rui Barradas
    Nov 15 '18 at 9:52













  • This actually works!!. I´m a rookie in regards to R. Thank you!!!

    – Angel Lopez Oriona
    Nov 15 '18 at 10:00








1




1





Welcome to SO. Your question is not a good one and is likely to bring in some downvotes if not edited: stackoverflow.com/help/how-to-ask

– sindri_baldur
Nov 15 '18 at 9:47







Welcome to SO. Your question is not a good one and is likely to bring in some downvotes if not edited: stackoverflow.com/help/how-to-ask

– sindri_baldur
Nov 15 '18 at 9:47






1




1





write.table(part[[i]], paste0(i, ".txt") Or maybe sprintf("%02d.txt", i) instead of paste0.

– Rui Barradas
Nov 15 '18 at 9:52







write.table(part[[i]], paste0(i, ".txt") Or maybe sprintf("%02d.txt", i) instead of paste0.

– Rui Barradas
Nov 15 '18 at 9:52















This actually works!!. I´m a rookie in regards to R. Thank you!!!

– Angel Lopez Oriona
Nov 15 '18 at 10:00





This actually works!!. I´m a rookie in regards to R. Thank you!!!

– Angel Lopez Oriona
Nov 15 '18 at 10:00












2 Answers
2






active

oldest

votes


















1














Use



for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}





share|improve this answer
























  • Ideally, explain your answer a bit to make it better.

    – Tjebo
    Nov 15 '18 at 11:41











  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rui Barradas
    Nov 15 '18 at 11:44











  • @Rui Barradas Why does this not answer the question? If you check the shared screenshot, I have just modified his existing code.

    – Rage
    Nov 15 '18 at 11:50



















0














How about using list.files()



That lists all the files in the current directory. or you can specify a directory as the first element of the function.






share|improve this answer



















  • 1





    This doesn't answer the question, the OP wants to write files, not to know the files that already exist in the directory.

    – Rui Barradas
    Nov 15 '18 at 9:54











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%2f53316514%2fhow-to-create-external-folder-in-a-loop-in-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Use



for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}





share|improve this answer
























  • Ideally, explain your answer a bit to make it better.

    – Tjebo
    Nov 15 '18 at 11:41











  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rui Barradas
    Nov 15 '18 at 11:44











  • @Rui Barradas Why does this not answer the question? If you check the shared screenshot, I have just modified his existing code.

    – Rage
    Nov 15 '18 at 11:50
















1














Use



for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}





share|improve this answer
























  • Ideally, explain your answer a bit to make it better.

    – Tjebo
    Nov 15 '18 at 11:41











  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rui Barradas
    Nov 15 '18 at 11:44











  • @Rui Barradas Why does this not answer the question? If you check the shared screenshot, I have just modified his existing code.

    – Rage
    Nov 15 '18 at 11:50














1












1








1







Use



for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}





share|improve this answer













Use



for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 9:58









RageRage

18312




18312













  • Ideally, explain your answer a bit to make it better.

    – Tjebo
    Nov 15 '18 at 11:41











  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rui Barradas
    Nov 15 '18 at 11:44











  • @Rui Barradas Why does this not answer the question? If you check the shared screenshot, I have just modified his existing code.

    – Rage
    Nov 15 '18 at 11:50



















  • Ideally, explain your answer a bit to make it better.

    – Tjebo
    Nov 15 '18 at 11:41











  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rui Barradas
    Nov 15 '18 at 11:44











  • @Rui Barradas Why does this not answer the question? If you check the shared screenshot, I have just modified his existing code.

    – Rage
    Nov 15 '18 at 11:50

















Ideally, explain your answer a bit to make it better.

– Tjebo
Nov 15 '18 at 11:41





Ideally, explain your answer a bit to make it better.

– Tjebo
Nov 15 '18 at 11:41













This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

– Rui Barradas
Nov 15 '18 at 11:44





This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

– Rui Barradas
Nov 15 '18 at 11:44













@Rui Barradas Why does this not answer the question? If you check the shared screenshot, I have just modified his existing code.

– Rage
Nov 15 '18 at 11:50





@Rui Barradas Why does this not answer the question? If you check the shared screenshot, I have just modified his existing code.

– Rage
Nov 15 '18 at 11:50













0














How about using list.files()



That lists all the files in the current directory. or you can specify a directory as the first element of the function.






share|improve this answer



















  • 1





    This doesn't answer the question, the OP wants to write files, not to know the files that already exist in the directory.

    – Rui Barradas
    Nov 15 '18 at 9:54
















0














How about using list.files()



That lists all the files in the current directory. or you can specify a directory as the first element of the function.






share|improve this answer



















  • 1





    This doesn't answer the question, the OP wants to write files, not to know the files that already exist in the directory.

    – Rui Barradas
    Nov 15 '18 at 9:54














0












0








0







How about using list.files()



That lists all the files in the current directory. or you can specify a directory as the first element of the function.






share|improve this answer













How about using list.files()



That lists all the files in the current directory. or you can specify a directory as the first element of the function.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 9:51









Oliver HumphreysOliver Humphreys

90110




90110








  • 1





    This doesn't answer the question, the OP wants to write files, not to know the files that already exist in the directory.

    – Rui Barradas
    Nov 15 '18 at 9:54














  • 1





    This doesn't answer the question, the OP wants to write files, not to know the files that already exist in the directory.

    – Rui Barradas
    Nov 15 '18 at 9:54








1




1





This doesn't answer the question, the OP wants to write files, not to know the files that already exist in the directory.

– Rui Barradas
Nov 15 '18 at 9:54





This doesn't answer the question, the OP wants to write files, not to know the files that already exist in the directory.

– Rui Barradas
Nov 15 '18 at 9:54


















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%2f53316514%2fhow-to-create-external-folder-in-a-loop-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

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python