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!
This is how I normally do,
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
Let me know if this works for you.
Best,
Eric