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

  • Home
  • SEARCH
  • 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 7730061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:07:43+00:00 2026-06-01T06:07:43+00:00

I have a short loop I used to create several .csv files. The loop

  • 0

I have a short loop I used to create several .csv files. The loop works and the files are created correctly, and I can open them in Microsoft Excel. Everything looks great. But when I try to read these files back into R in another script, R doesn’t recognize them.

Do you need to turn off some sort of driver inside the loop as you would if you were creating several png files?

Here is the loop (works). For reference, dtlm is a large dataframe with several columns including “diag”, “county” and “date” and “Freq”.

single = c("492", "493", "427", "428", "786")
for (q in 1:length(single))  {
    xx = xtabs(~date+county, data=dtlm, subset = dtlm$diag == single[q])
    xy=as.data.frame(xx)
    write.csv(xy, paste(single[q], ".csv", sep=""))
}

Now here is an example of a command that R can’t recognize the file with:

dt <- read.csv("C:/Users/myname/Desktop/FreqTables/492.csv")

So weird! I have also tried read.table and that didn’t work either, and I didn’t find anything helpful in ?read.csv. Any suggestions would be greatly appreciated!

  • 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-01T06:07:44+00:00Added an answer on June 1, 2026 at 6:07 am

    This is how I normally do,

    ## store the path in some object, here 'dir'
    dir <- "[path to the folder where you have your data]"
    
    ## then pick up the file names from the 'dir,' change the filter as needed
    fnames <- list.files(path = dir, pattern = ".csv")
    
    ## read the data into a list
    dfn = list()
    for (string in fnames){
    dfn[[string]]=read.csv(paste(dir,string,sep = ""))
    }
    

    You can probably do it in fewer lines, but this works for me.

    If you like to merge the files together you can use something like this, note that I bring in the file name from the csv files

    ## remove the .csv suffix
    names(dfn) <- strsplit(names(dfn),".csv")
    
    ## merging the data frames together (traditional)
    DF <- dfn[[1]]
    for ( .df in dfn) {
    DF <-merge(DF, .df, by.x="ID", by.y="ID", all.x=T,
               suffixes=paste(":", names(dfn), sep = ""))
    }    
    

    Let me know if this works for you.

    Best,
    Eric

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

Sidebar

Related Questions

I have used the NameAndPassword Auth Plugin sample code from Apple to create my
I have an article system which is used by several users. Articles have their
I am coding a messaging system and I don't want to have short IDs
I have a short question. Im my current project I'm using LINQ-to-SQl. That is
I have a short version of the question: I start a thread like that:
I have a short question, let's assume I have a TabBarController with 3 Tabs
I have a short question. I want do put this \tssr>&\8=f23' into a String
I'm trying to figure out how to have a short, one line conditional statement.
In short: I have two matrices (or arrays): import numpy block_1 = numpy.matrix([[ 0,
I have the following short version of a tsql if else if.. IF @var

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.