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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:28:26+00:00 2026-06-07T04:28:26+00:00

I wrote the following script to generate several plot in a for loop which

  • 0

I wrote the following script to generate several plot in a for loop which works well:

stat <- list.files("D:/...", pattern = "met")

par(mfrow = c(4, 4))
for (x in stat) {
plot((assign(x, read.csv(x, head=TRUE, sep=""))),typ="l", col="red")
}

What I would like to achieve now is to add the title of each graph recursively according to the name of the file that is read.

Hope this is clear,

Best,

P.S.
I also have another curiosity but I will leave this maybe for after.

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-06-07T04:28:27+00:00Added an answer on June 7, 2026 at 4:28 am

    Does adding the title (main) argument to plot do what you’re looking for?

    plot((assign(x, read.csv(x, head=TRUE, sep=""))),typ="l", col="red", main=x)
    

    edited for OPs comment

    you can use gsub for this.

    plot((assign(gsub('\\.txt', '', x), 
          read.csv(x, head=TRUE, sep=""))),
         typ="l", 
         col="red", 
         main=gsub('\\.txt', '', x))
    

    However, the looping assign construct you’re using is a dangerous one to get in the habit of using. Usually this would be done by reading all the files in as a list and then lapply across them, or some variation on that theme.

    You should be able to skip the assign step altogether unless you’re doing additional processing after this plot step.

    plot(read.csv(x, head=TRUE, sep=""),
         typ="l",
         col="red",
         main=gsub('\\.txt', '', x))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following script, which generates a SyntaxError : #!/usr/bin/python print Enter the
I have an interesting problem. I wrote the following perl script to recursively loop
following is the bash script I wrote for Sqlite. #!/bin/bash sqlite3 file.db CREATE TABLE
I wrote the following Perl script (below) in order to create simple XML file.
Let's say I used the following command to create a User model: script/generate model
Does anybody know of a proc or script which will generate any row into
Currently, I have a script which does the following. If I have text file
I have recently started learning MatLab, and wrote the following script today as part
I have a directory in my mac which has files with following names -
I need to write a script which merges a list with a dictionary to

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.