0

I'm looping in data frames based off of IDs in the names of CSVs in R.

I want to further manipulate the data frames once I create them in the loop.

The code works up until the last line of the code, outfile<-cbind(outfile,ID). This simply creates a variable named outfile. I want it to reference the most recent data frame just created in a loop. I've tried paste(outfile)<-cbind but I get the error " could not find function "paste<-"".

for (ID in IDs) {
  infile<-paste("data/raw_data/DEV001/DEV001ID",ID,"_Sensor1_Raw.csv",sep="")
  outfile<-paste("DEV002ID",ID,"Raw",sep="")
importing<-read.csv(file=infile,header=TRUE,sep=',') #import dataset
assign(outfile,importing)
outfile<-cbind(outfile,ID)
}
ESIRMITS
  • 19
  • 5
  • 2
    The best advice is not to use `assign()`. It's not a very R like function. You should be putting related elements into a named list rather than creating a bunch of separate objects in your global workspace. Then you can easily apply whatever functions you like over that list. See [how do I make a list of data.frames](https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) for more info – MrFlick May 16 '22 at 20:52
  • Thanks @MrFlick! I think I made this work out. – ESIRMITS May 16 '22 at 22:08

0 Answers0