[R] assign a data frame name from a list in do loop

Kai Yang y@ngk@|9999 @end|ng |rom y@hoo@com
Wed Jul 14 17:55:39 CEST 2021


Hello List,
I wrote a script below to compare the difference of data frames structure (and will do something else). First of all I save the file list in a data frame ora, then I use for loop to 1. load the data from two resource, 2. generate data structure into two data frames, 3.do the comparesion of the two data frames of data structure and put it into a data frame, 4. remove the useless data frames for next loop
for (j in 1:nrow(ora))
{
  mycol  <- ora[j,"fname"]
#--------------------work on csv------------  
  mycsv  <- paste0(mycol,".csv")
  rdcsv  <- noquote(paste0("w:/project/_Joe.B/Oracle/data/", mycsv))
  rr     <- read.csv(rdcsv)

#--------------------work on SS ------------  
  myss   <- paste0("gemd.", mycol)
  rdss   <- paste0('select * from ',myss)
  ss     <- dbGetQuery(con, rdss)
  
#--------------------compare DF structure   ------------  
str_rr <- as.data.frame(summary.default(rr))
str_ss <- as.data.frame(summary.default(ss))


sdif_[j] <- sqldf('select * from str_rr except select * from str_ss')

#---------remove data frame from memory--------------

  rm(rr)
  rm(ss)
  rm(str_rr)
  rm(str_ss)
}
In the step 3, I want to use ora$fname in the loop to assign a data frame name. So, I will look the output later. But sdif_[j] doesn't work for this. Can someone help me to fix this part?
Thanks,
Kai
	[[alternative HTML version deleted]]



More information about the R-help mailing list