Message-ID: <2fa0edf4-a6d0-10e5-47ce-f5da7ef25a06@sapo.pt>
Date: 2021-07-14T17:07:45Z
From: Rui Barradas
Subject: assign a data frame name from a list in do loop
In-Reply-To: <917452799.2541098.1626278139658@mail.yahoo.com>
Hello,
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
file.path:
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 at 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.
https://www.avast.com/antivirus