How to create external folder in a loop in R?
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
add a comment |
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
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 maybesprintf("%02d.txt", i)
instead ofpaste0
.
– 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
add a comment |
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
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
r
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 maybesprintf("%02d.txt", i)
instead ofpaste0
.
– 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
add a comment |
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 maybesprintf("%02d.txt", i)
instead ofpaste0
.
– 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
add a comment |
2 Answers
2
active
oldest
votes
Use
for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}
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
add a comment |
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Use
for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}
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
add a comment |
Use
for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}
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
add a comment |
Use
for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}
Use
for(i in 1:(length(vec)-1)){
write.table(part[[i]],paste(i,"txt",sep = "."))
}
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 maybesprintf("%02d.txt", i)
instead ofpaste0
.– 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