Batch processing multiple .csv files using R selecting only one columnDealing with commas in a CSV fileHow to sort a dataframe by multiple column(s)Save PL/pgSQL output from PostgreSQL to a CSV fileHow to import CSV file to MySQL tableHow to import multiple .csv files at once?Read specific columns from a csv file with csv module?Combining csv files in R to different columnsLooping and extracting file numbers from .csv file names and inserting into a columnImport multiple CSV files, select 1 Column from each file & rename the column with the file name in Jupyter NoteboosBatch file for replace characters in all CSV of a folder

If I arrive in the UK, and then head to mainland Europe, does my Schengen visa 90 day limit start when I arrived in the UK, or mainland Europe?

Best shape for a necromancer's undead minions for battle?

Is there a simple example that empirical evidence is misleading?

Is superuser the same as root?

Why isn't Tyrion mentioned in the in-universe book "A Song of Ice and Fire"?

Did this character show any indication of wanting to rule before S8E6?

Is keeping the forking link on a true fork necessary (Github/GPL)?

Security vulnerabilities of POST over SSL

Job Market: should one hide their (young) age?

Apart from the sine wave, are there any other waveshapes that could be thought of as commonly appearing "in nature"?

Why would a rational buyer offer to buy with no conditions precedent?

How to let other coworkers know that I don't share my coworker's political views?

Count all vowels in string

How did NASA Langley end up with the first 737?

Freedom of Speech and Assembly in China

Heat lost in ideal capacitor charging

How to keep consistency across the application architecture as a team grows?

Of strange atmospheres - the survivable but unbreathable

Why did it take so long for Germany to allow electric scooters / e-rollers on the roads?

What weight should be given to writers groups critiques?

Grade-school elementary algebra presented in an abstract-algebra style?

Sorting with IComparable design

Navigating a quick return to previous employer

Natural Armour and Weapons



Batch processing multiple .csv files using R selecting only one column


Dealing with commas in a CSV fileHow to sort a dataframe by multiple column(s)Save PL/pgSQL output from PostgreSQL to a CSV fileHow to import CSV file to MySQL tableHow to import multiple .csv files at once?Read specific columns from a csv file with csv module?Combining csv files in R to different columnsLooping and extracting file numbers from .csv file names and inserting into a columnImport multiple CSV files, select 1 Column from each file & rename the column with the file name in Jupyter NoteboosBatch file for replace characters in all CSV of a folder






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I am working on a project that involves 470 stats kept over a period of 40 years. My data is structured so that each year is a folder and its 470 corresponding stats (as .csv files) are kept inside that folder. Each of these files contains an ascending or descending column of numbers (inside the same .csv file) of which I care about. I need to know what column number this is for every .csv file.



Here is my problem. The information file of which I have been given that explains to me each of these stats is mislabeled. It tells me that the meaningful data is in column 4 for every .csv file (data_col = 4 for all attributes); however, this is only correct for 80-90% of the files from my observations.



I want to batch import column 4 from each file into one large data set (470 columns; each representing a stat) so I can see if the data in that column is ascending or descending. If it is not, I can manually open that file and find it myself. I can then modify my information file so I know which columns to run my analysis on later.



The alternative to this is opening and closing 470 files for each year (or 40 times) and looking to see if the data is in column 4 as stated.



How do I batch import a single column from multiple .csv files into one dataset in R?










share|improve this question






















  • Please have a look at the help center and try to put some code together, test it yourself and then ask here only what you cannot figure out on your own (with your coding attempt) otherwise it's impossible to help you and it looks like you're just asking us to do your work for you.

    – Fons MA
    Mar 24 at 1:47

















-1















I am working on a project that involves 470 stats kept over a period of 40 years. My data is structured so that each year is a folder and its 470 corresponding stats (as .csv files) are kept inside that folder. Each of these files contains an ascending or descending column of numbers (inside the same .csv file) of which I care about. I need to know what column number this is for every .csv file.



Here is my problem. The information file of which I have been given that explains to me each of these stats is mislabeled. It tells me that the meaningful data is in column 4 for every .csv file (data_col = 4 for all attributes); however, this is only correct for 80-90% of the files from my observations.



I want to batch import column 4 from each file into one large data set (470 columns; each representing a stat) so I can see if the data in that column is ascending or descending. If it is not, I can manually open that file and find it myself. I can then modify my information file so I know which columns to run my analysis on later.



The alternative to this is opening and closing 470 files for each year (or 40 times) and looking to see if the data is in column 4 as stated.



How do I batch import a single column from multiple .csv files into one dataset in R?










share|improve this question






















  • Please have a look at the help center and try to put some code together, test it yourself and then ask here only what you cannot figure out on your own (with your coding attempt) otherwise it's impossible to help you and it looks like you're just asking us to do your work for you.

    – Fons MA
    Mar 24 at 1:47













-1












-1








-1








I am working on a project that involves 470 stats kept over a period of 40 years. My data is structured so that each year is a folder and its 470 corresponding stats (as .csv files) are kept inside that folder. Each of these files contains an ascending or descending column of numbers (inside the same .csv file) of which I care about. I need to know what column number this is for every .csv file.



Here is my problem. The information file of which I have been given that explains to me each of these stats is mislabeled. It tells me that the meaningful data is in column 4 for every .csv file (data_col = 4 for all attributes); however, this is only correct for 80-90% of the files from my observations.



I want to batch import column 4 from each file into one large data set (470 columns; each representing a stat) so I can see if the data in that column is ascending or descending. If it is not, I can manually open that file and find it myself. I can then modify my information file so I know which columns to run my analysis on later.



The alternative to this is opening and closing 470 files for each year (or 40 times) and looking to see if the data is in column 4 as stated.



How do I batch import a single column from multiple .csv files into one dataset in R?










share|improve this question














I am working on a project that involves 470 stats kept over a period of 40 years. My data is structured so that each year is a folder and its 470 corresponding stats (as .csv files) are kept inside that folder. Each of these files contains an ascending or descending column of numbers (inside the same .csv file) of which I care about. I need to know what column number this is for every .csv file.



Here is my problem. The information file of which I have been given that explains to me each of these stats is mislabeled. It tells me that the meaningful data is in column 4 for every .csv file (data_col = 4 for all attributes); however, this is only correct for 80-90% of the files from my observations.



I want to batch import column 4 from each file into one large data set (470 columns; each representing a stat) so I can see if the data in that column is ascending or descending. If it is not, I can manually open that file and find it myself. I can then modify my information file so I know which columns to run my analysis on later.



The alternative to this is opening and closing 470 files for each year (or 40 times) and looking to see if the data is in column 4 as stated.



How do I batch import a single column from multiple .csv files into one dataset in R?







r csv batch-processing dynamic-columns






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 23:53









sharkguy95sharkguy95

12




12












  • Please have a look at the help center and try to put some code together, test it yourself and then ask here only what you cannot figure out on your own (with your coding attempt) otherwise it's impossible to help you and it looks like you're just asking us to do your work for you.

    – Fons MA
    Mar 24 at 1:47

















  • Please have a look at the help center and try to put some code together, test it yourself and then ask here only what you cannot figure out on your own (with your coding attempt) otherwise it's impossible to help you and it looks like you're just asking us to do your work for you.

    – Fons MA
    Mar 24 at 1:47
















Please have a look at the help center and try to put some code together, test it yourself and then ask here only what you cannot figure out on your own (with your coding attempt) otherwise it's impossible to help you and it looks like you're just asking us to do your work for you.

– Fons MA
Mar 24 at 1:47





Please have a look at the help center and try to put some code together, test it yourself and then ask here only what you cannot figure out on your own (with your coding attempt) otherwise it's impossible to help you and it looks like you're just asking us to do your work for you.

– Fons MA
Mar 24 at 1:47












1 Answer
1






active

oldest

votes


















0














This will get all the CSV files in a directory and then read them into a single data.frame only keeping column 4 (or whatever columns you want to keep), and also put the file name in each row if you want to find errors in the input



library(tidyverse) # get useful functions
files <- list.files(path = '/d$/temp/csv',
pattern = ".*csv",
full.names = TRUE
)
all_data <- map_dfr(files, ~
read_csv(.x)[, 4] %>% # keep column 4
mutate(file = .x) # add file name
)
print(all_data[1:10,])

col4 file
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv
4 /d$/temp/csv/Document1 - Copy (2).csv


The CSV files looked like this:



col1,col2,col3,col4,col5,col6
1,2,3,4,5,6
1,2,3,4,5,6





share|improve this answer























    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%2f55319474%2fbatch-processing-multiple-csv-files-using-r-selecting-only-one-column%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This will get all the CSV files in a directory and then read them into a single data.frame only keeping column 4 (or whatever columns you want to keep), and also put the file name in each row if you want to find errors in the input



    library(tidyverse) # get useful functions
    files <- list.files(path = '/d$/temp/csv',
    pattern = ".*csv",
    full.names = TRUE
    )
    all_data <- map_dfr(files, ~
    read_csv(.x)[, 4] %>% # keep column 4
    mutate(file = .x) # add file name
    )
    print(all_data[1:10,])

    col4 file
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv
    4 /d$/temp/csv/Document1 - Copy (2).csv


    The CSV files looked like this:



    col1,col2,col3,col4,col5,col6
    1,2,3,4,5,6
    1,2,3,4,5,6





    share|improve this answer



























      0














      This will get all the CSV files in a directory and then read them into a single data.frame only keeping column 4 (or whatever columns you want to keep), and also put the file name in each row if you want to find errors in the input



      library(tidyverse) # get useful functions
      files <- list.files(path = '/d$/temp/csv',
      pattern = ".*csv",
      full.names = TRUE
      )
      all_data <- map_dfr(files, ~
      read_csv(.x)[, 4] %>% # keep column 4
      mutate(file = .x) # add file name
      )
      print(all_data[1:10,])

      col4 file
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv
      4 /d$/temp/csv/Document1 - Copy (2).csv


      The CSV files looked like this:



      col1,col2,col3,col4,col5,col6
      1,2,3,4,5,6
      1,2,3,4,5,6





      share|improve this answer

























        0












        0








        0







        This will get all the CSV files in a directory and then read them into a single data.frame only keeping column 4 (or whatever columns you want to keep), and also put the file name in each row if you want to find errors in the input



        library(tidyverse) # get useful functions
        files <- list.files(path = '/d$/temp/csv',
        pattern = ".*csv",
        full.names = TRUE
        )
        all_data <- map_dfr(files, ~
        read_csv(.x)[, 4] %>% # keep column 4
        mutate(file = .x) # add file name
        )
        print(all_data[1:10,])

        col4 file
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv


        The CSV files looked like this:



        col1,col2,col3,col4,col5,col6
        1,2,3,4,5,6
        1,2,3,4,5,6





        share|improve this answer













        This will get all the CSV files in a directory and then read them into a single data.frame only keeping column 4 (or whatever columns you want to keep), and also put the file name in each row if you want to find errors in the input



        library(tidyverse) # get useful functions
        files <- list.files(path = '/d$/temp/csv',
        pattern = ".*csv",
        full.names = TRUE
        )
        all_data <- map_dfr(files, ~
        read_csv(.x)[, 4] %>% # keep column 4
        mutate(file = .x) # add file name
        )
        print(all_data[1:10,])

        col4 file
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv
        4 /d$/temp/csv/Document1 - Copy (2).csv


        The CSV files looked like this:



        col1,col2,col3,col4,col5,col6
        1,2,3,4,5,6
        1,2,3,4,5,6






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 2:03









        Data MungerData Munger

        96566




        96566





























            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%2f55319474%2fbatch-processing-multiple-csv-files-using-r-selecting-only-one-column%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript