[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 19:30:02 CEST 2021

 Hello Rui,
it's very helpful. 
Thank you,
    On Wednesday, July 14, 2021, 10:07:57 AM PDT, Rui Barradas <ruipbarradas using sapo.pt> wrote:  

Just before for(j in 1:nrow(ora)) include the following code line (I 
have removed the underscore):

sdif <- vector("list", length = nrow(ora))

In the loop:

sdif[[j]] <- sqldf(etc)

Also, once again, why noquote? It's better to form file names with 

rdcsv  <- file.path("w:/project/_Joe.B/Oracle/data", mycsv)

Hope this helps,

Rui Barradas

Às 16:55 de 14/07/2021, Kai Yang via R-help escreveu:
> 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]]
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.

	[[alternative HTML version deleted]]

More information about the R-help mailing list