split files from different folders with loop in R [on hold]












0















I have different folders that all contain only one CSV file. I want to split all files from every folder on the basis of CN in there own place
This is position of files :-



home -> folder -> folder_44748 -> 44748.csv
-> folder_44749 -> 44749.csv
-> folder_44751 -> 44751.csv


This is my code in R:-



Edits:



> dir <- "/home/folder"
my_dirs <- list.dirs(dir, recursive = FALSE)

> for(i in my_dirs){
a <- list.files(path = i, full.names = TRUE, recursive = TRUE)
df <- read.csv(a)
a0 <- df[df$CN=="cn=0",]
a1 <- df[df$CN=="cn=1",]
a3 <- df[df$CN=="cn=3",]
a4 <- df[df$CN=="cn=4",]
write.csv(a0,"cn0.csv")
write.csv(a1,"cn1.csv")
write.csv(a3,"cn3.csv")
write.csv(a4,"cn4.csv")
}


I am new with programming so please tell me how to specify path for each folder to save results










share|improve this question









New contributor




Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels

If this question can be reworded to fit the rules in the help center, please edit the question.














  • Should the call to i be in there? it's not a function I've heard of

    – Russ Hyde
    yesterday











  • I was trying to do this with loop but its not working. " i " will indicate the path The program should work like go to 1st folder -> read the csv file -> split it -> save it then move to 2nd folder -> read the csv file -> split -> save it then move to next

    – Rochi Saurabh
    yesterday











  • But surely write.csv(i(a4,"cn4.csv")) doesn't run at the moment, unless you've got something other than base-R in your env. Can you edit your code and check that it runs, please.

    – Russ Hyde
    yesterday











  • See edits: This program will generate files at /home/folder but it overwrite for all samples and I want to create output folder in every folder so my problem is how to define path of every folder

    – Rochi Saurabh
    22 hours ago
















0















I have different folders that all contain only one CSV file. I want to split all files from every folder on the basis of CN in there own place
This is position of files :-



home -> folder -> folder_44748 -> 44748.csv
-> folder_44749 -> 44749.csv
-> folder_44751 -> 44751.csv


This is my code in R:-



Edits:



> dir <- "/home/folder"
my_dirs <- list.dirs(dir, recursive = FALSE)

> for(i in my_dirs){
a <- list.files(path = i, full.names = TRUE, recursive = TRUE)
df <- read.csv(a)
a0 <- df[df$CN=="cn=0",]
a1 <- df[df$CN=="cn=1",]
a3 <- df[df$CN=="cn=3",]
a4 <- df[df$CN=="cn=4",]
write.csv(a0,"cn0.csv")
write.csv(a1,"cn1.csv")
write.csv(a3,"cn3.csv")
write.csv(a4,"cn4.csv")
}


I am new with programming so please tell me how to specify path for each folder to save results










share|improve this question









New contributor




Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels

If this question can be reworded to fit the rules in the help center, please edit the question.














  • Should the call to i be in there? it's not a function I've heard of

    – Russ Hyde
    yesterday











  • I was trying to do this with loop but its not working. " i " will indicate the path The program should work like go to 1st folder -> read the csv file -> split it -> save it then move to 2nd folder -> read the csv file -> split -> save it then move to next

    – Rochi Saurabh
    yesterday











  • But surely write.csv(i(a4,"cn4.csv")) doesn't run at the moment, unless you've got something other than base-R in your env. Can you edit your code and check that it runs, please.

    – Russ Hyde
    yesterday











  • See edits: This program will generate files at /home/folder but it overwrite for all samples and I want to create output folder in every folder so my problem is how to define path of every folder

    – Rochi Saurabh
    22 hours ago














0












0








0








I have different folders that all contain only one CSV file. I want to split all files from every folder on the basis of CN in there own place
This is position of files :-



home -> folder -> folder_44748 -> 44748.csv
-> folder_44749 -> 44749.csv
-> folder_44751 -> 44751.csv


This is my code in R:-



Edits:



> dir <- "/home/folder"
my_dirs <- list.dirs(dir, recursive = FALSE)

> for(i in my_dirs){
a <- list.files(path = i, full.names = TRUE, recursive = TRUE)
df <- read.csv(a)
a0 <- df[df$CN=="cn=0",]
a1 <- df[df$CN=="cn=1",]
a3 <- df[df$CN=="cn=3",]
a4 <- df[df$CN=="cn=4",]
write.csv(a0,"cn0.csv")
write.csv(a1,"cn1.csv")
write.csv(a3,"cn3.csv")
write.csv(a4,"cn4.csv")
}


I am new with programming so please tell me how to specify path for each folder to save results










share|improve this question









New contributor




Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have different folders that all contain only one CSV file. I want to split all files from every folder on the basis of CN in there own place
This is position of files :-



home -> folder -> folder_44748 -> 44748.csv
-> folder_44749 -> 44749.csv
-> folder_44751 -> 44751.csv


This is my code in R:-



Edits:



> dir <- "/home/folder"
my_dirs <- list.dirs(dir, recursive = FALSE)

> for(i in my_dirs){
a <- list.files(path = i, full.names = TRUE, recursive = TRUE)
df <- read.csv(a)
a0 <- df[df$CN=="cn=0",]
a1 <- df[df$CN=="cn=1",]
a3 <- df[df$CN=="cn=3",]
a4 <- df[df$CN=="cn=4",]
write.csv(a0,"cn0.csv")
write.csv(a1,"cn1.csv")
write.csv(a3,"cn3.csv")
write.csv(a4,"cn4.csv")
}


I am new with programming so please tell me how to specify path for each folder to save results







beginner r






share|improve this question









New contributor




Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 14 hours ago







Rochi Saurabh













New contributor




Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Rochi SaurabhRochi Saurabh

12




12




New contributor




Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Rochi Saurabh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, Ludisposed, Sᴀᴍ Onᴇᴌᴀ, Hosch250, IEatBagels

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Should the call to i be in there? it's not a function I've heard of

    – Russ Hyde
    yesterday











  • I was trying to do this with loop but its not working. " i " will indicate the path The program should work like go to 1st folder -> read the csv file -> split it -> save it then move to 2nd folder -> read the csv file -> split -> save it then move to next

    – Rochi Saurabh
    yesterday











  • But surely write.csv(i(a4,"cn4.csv")) doesn't run at the moment, unless you've got something other than base-R in your env. Can you edit your code and check that it runs, please.

    – Russ Hyde
    yesterday











  • See edits: This program will generate files at /home/folder but it overwrite for all samples and I want to create output folder in every folder so my problem is how to define path of every folder

    – Rochi Saurabh
    22 hours ago



















  • Should the call to i be in there? it's not a function I've heard of

    – Russ Hyde
    yesterday











  • I was trying to do this with loop but its not working. " i " will indicate the path The program should work like go to 1st folder -> read the csv file -> split it -> save it then move to 2nd folder -> read the csv file -> split -> save it then move to next

    – Rochi Saurabh
    yesterday











  • But surely write.csv(i(a4,"cn4.csv")) doesn't run at the moment, unless you've got something other than base-R in your env. Can you edit your code and check that it runs, please.

    – Russ Hyde
    yesterday











  • See edits: This program will generate files at /home/folder but it overwrite for all samples and I want to create output folder in every folder so my problem is how to define path of every folder

    – Rochi Saurabh
    22 hours ago

















Should the call to i be in there? it's not a function I've heard of

– Russ Hyde
yesterday





Should the call to i be in there? it's not a function I've heard of

– Russ Hyde
yesterday













I was trying to do this with loop but its not working. " i " will indicate the path The program should work like go to 1st folder -> read the csv file -> split it -> save it then move to 2nd folder -> read the csv file -> split -> save it then move to next

– Rochi Saurabh
yesterday





I was trying to do this with loop but its not working. " i " will indicate the path The program should work like go to 1st folder -> read the csv file -> split it -> save it then move to 2nd folder -> read the csv file -> split -> save it then move to next

– Rochi Saurabh
yesterday













But surely write.csv(i(a4,"cn4.csv")) doesn't run at the moment, unless you've got something other than base-R in your env. Can you edit your code and check that it runs, please.

– Russ Hyde
yesterday





But surely write.csv(i(a4,"cn4.csv")) doesn't run at the moment, unless you've got something other than base-R in your env. Can you edit your code and check that it runs, please.

– Russ Hyde
yesterday













See edits: This program will generate files at /home/folder but it overwrite for all samples and I want to create output folder in every folder so my problem is how to define path of every folder

– Rochi Saurabh
22 hours ago





See edits: This program will generate files at /home/folder but it overwrite for all samples and I want to create output folder in every folder so my problem is how to define path of every folder

– Rochi Saurabh
22 hours ago










0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Terni

A new problem with tex4ht and tikz

Sun Ra