I'm trying to execute the same functions over a group of 6 dataframes
I tried two possibilities:
DATAFRAMES <- c("df_IEC", "df_IVA", "df_MDC", "df_MDE", "df_SALV", "df_VIES")
for (item in DATAFRAMES) {
# examine dataframe
glimpse(item)
dim(item)
str(item)
# some statistics
summary(item)
}
and this one:
DATAFRAMES <- as.list(c("df_IEC", "df_IVA", "df_MDC", "df_MDE", "df_SALV", "df_VIES"))
ANALISE_RESUMO <- function(x) {
glimpse(x)
dim(x)
str(x)
# some statistics
summary(x)
}
result <- sapply(DATAFRAMES, ANALISE_RESUMO)
print(result)
Both of them considered the elements in the list or vector as text and not as a group of dataframes.
How can I solve this?
In the function ANALISE_RESUMO
you should convert the name in the object.
E.g. with the get
function
dfname <- 'iris'
df <- get(dfname)
1 Like
@HanOostdijk
Just like this:
ANALISE_RESUMO <- function(x) {
dfname <- 'x'
df <- get(dfname)
glimpse(df)
dim(df)
str(df)
# some statistics
summary(df)
}
@HanOostdijk
This code worked correctly:
DATAFRAMES <- c("df_IEC", "df_IVA", "df_MDC", "df_MDE", "df_SALV", "df_VIES")
ANALISE_RESUMO <- function(x) {
# examine dataframe
glimpse(x)
dim(x)
str(x)
# some statistics
summary(x)
}
# Loop through the data frames
for (item in DATAFRAMES) {
df <- get(item)
ANALISE_RESUMO(df)
}
system
Closed
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.