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 8419847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:43:41+00:00 2026-06-10T02:43:41+00:00

I am trying to manage multiple files in R but am having a difficult

  • 0

I am trying to manage multiple files in R but am having a difficult time of it. I want to take the data in each of these files and manipulate them through a series of steps (all files receiving the same treatment). I think that I am going about it in a very silly manner though. Is there a way to manage many files (each the same a before) without using 900 apply statements? For example, when is it recommended you merge all the data frames rather that treat each separately? Is there a way to merge more than two, or an uncertain number, as with the way the files are input here? Or is there a better way to handle so many files?

I take files in a standard way:

chosen<-(tk_choose.files(default="", caption="Files:", multi=TRUE, filters=NULL, index=1))

But after that I would like to do several things with the data. As of now I am just apply different things but it is getting confusing. See:

ytrim<-lapply(chosen, function(x) strtrim(y, width=11))
chRead<-lapply(chosen,read.table,header=TRUE)
tmp<-lapply(inputFiles, function(x) stack(fnctn))

etc, etc. This surely can’t be the recommended way to go about it. Is there a better way to handle a multitude of files?

  • 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-06-10T02:43:42+00:00Added an answer on June 10, 2026 at 2:43 am

    You can write one function with all operations, and apply it to all your files like this:

    doSomethingWithFile <- function(filename) {
        ytrim <- strtrim(filename, width=11))
        chRead<- read.table(filename,header=TRUE)
        # Return some result
        chRead
    }
    
    result<-lapply(chosen, doSomethingWithFile)
    

    You will only need to think about how to return the results, as lapply needs to return a list with the same length as the input (chosen, in this case). You could also look at one of the apply functions of the plyr packages for more flexibility.

    (BTW: this code is not without errors, but neither is your example… I’ll update mine if you give a proper example)

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

Sidebar

Related Questions

I'm trying to get Django's manage.py to run with modified settings files. I have
I'm trying to use couchapp to manage my CouchDB application, but it's missing a
I'm trying to forbid multiple logins by the same user at the same time
I am trying to process multiple file writing commands (to seperate files) without hanging
I am trying to compress multiple files into a single zip archive and I
I am trying to figure out how to manage multiple lazy sequences from a
I'm trying to load multiple libraries in CI but I'm getting an error. Here
I'm a newbie to development, and for the first time, I'm trying to manage
I'm trying to use Twisted in a sort of spidering program that manages multiple
I am trying to manage session of users after authentication with ldap. The authentication

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.