Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:57:11+00:00 2026-05-25T02:57:11+00:00

I have hundreds of csv files (zoo objects in R) with 2 columns: Index,pp

  • 0

I have hundreds of csv files (zoo objects in R) with 2 columns:

"Index","pp"
1951-01-01,22.9
1951-01-02,4.3
1951-01-03,4.6

I want the second column to have the name of each file. For example, when a filename is 02O_zoo.csv I would like the second column to be “02O” instead of “pp”. Is there an automatic way of doing this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:57:12+00:00Added an answer on May 25, 2026 at 2:57 am

    (1) From files read.zoo can take a character vector of file names as its first argument so:

    # create test files
    Lines <- '"Index","pp"
    1951-01-01,22.9
    1951-01-02,4.3
    1951-01-03,4.6'
    cat(Lines, file = "testzoo01.csv")
    cat(Lines, file = "testzoo02.csv")
    
    # read.zoo reads the files named in Filenames and merges them
    library(zoo)
    Filenames <- dir(pattern = "testzoo.*csv")
    
    z <- read.zoo(Filenames, sep = ",", header = TRUE)
    

    which gives this:

    > z
               testzoo01.csv testzoo02.csv
    1951-01-01          22.9          22.9
    1951-01-02           4.3           4.3
    1951-01-03           4.6           4.6
    

    It would be possible to modify the names further if desired by placing names on the Filenames variable, e.g. names(Filenames) <- gsub("testzoo|.csv", "", Filenames), or by modifying the names of the result, e.g. names(z) <- gsub("testzoo|.csv", "", names(z))

    (2) From zoo Objects. If they have been read in previously then try this:

    # create test objects using Lines and library() statement from above
    testobj1 <- testobj2 <- read.zoo(textConnection(Lines), header = TRUE, sep = ",")
    
    # merge them into a single zoo object
    zz <- do.call(merge, sapply(ls(pattern = "testobj.*"), get, simplify = FALSE))
    

    which gives this:

    > zz
               testobj1 testobj2
    1951-01-01     22.9     22.9
    1951-01-02      4.3      4.3
    1951-01-03      4.6      4.6
    

    The names of zz could be modified further as in the discussion above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of CSV files with hundreds of columns and about 50,000
I have hundreds of CSV files zipped. This is great because they take very
I have loaded .csv file into the dataset. The csv file(have afew hundreds lines)
The situation: I have hundreds of excel files ( .xls and .xlsx ); each
I have a text file with hundreds of lines of data - each separated
I have hundreds of files in one folder named like this: index.html?tab=This is -
I have hundreds of stored procedures and i want to find out the name
I have hundreds of files containing text I want to use with NLTK. Here
i have hundreds of [mostly different] files in many different directories that all have
We have a database of hundreds urls which we want to show similar content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.