Thanks! this works very well...how would I go about naming each file I have just imported so I can easily call them up?
–
JonoJul 11 '12 at 13:34

if you can show us the first few lines of some of your files we might have some suggestions - edit your question for that!
–
SpacedmanJul 11 '12 at 14:13

1

The above code works perfectly for importing them as single objects but when I try to call up a column from the data set it doesnt recognise it as it is only a single object not a data frame i.e. my version of the above code is: setwd('C:/Users/new/Desktop/Dives/0904_003') temp<-list.files(pattern="*.csv") ddives <- lapply(temp, read.csv) So now each file is called ddives[n] but how would I go about writing a loop to make them all data frames rather than single objects? I can achieve this individually using the data.frame operator but am unsure as to how to loop this. @mrdwab
–
JonoJul 11 '12 at 15:07

@JosephOnoufriou, see my update. But generally, I find working with lists easier if I'm going to be doing similar calculations on all data frames.
–
Ananda MahtoJul 11 '12 at 15:56

1

For anyone trying to write a function to do the updated version of this answer using assign... If you want the assigned values to reside in the global environment, make sure you set inherits=T.
–
dnlbrkyApr 30 '14 at 2:06

This is the code I developed to read all csv files into R. It will create a dataframe for each csv file individually and title that dataframe the file's original name (removing spaces and the .csv) I hope you find it useful!

I can't comment, because I'm a n00b, so you'll have to forgive answering this question instead.
Ananda's answer above answers the original question perfectly for my use-case, but I wanted to add something that I had trouble finding: after importing all these CSV files, how do you then do anything with them? The answer is ls() and get().

temp = list.files(pattern=".csv$") #list all the files in dir that have .csv at the end
for (i in 1:length(temp)) {
assign(temp[i], prettify(toJSON(read.csv(temp[i])))) #read each csv, convert to JSON,make pretty, give it a name
write(get(temp[i]),paste(temp[i],"json", sep=".")) #write the json to a file
}

My use case was to import a bunch of CSV files, convert them to JSON, prettify them, then write them out to a .json file. If you removed the ".csv" from the name of your newly imported data frames, then you might need to use ls() to find your data frames again.