I have these three data frames and this function
set.seed(1)
df1 <-
data.frame(
x = c("cat", "dog"),
y = sample(1:100, 20),
z = seq(ymd("2020-01-01"), ymd("2020-01-20"), by = "1 day")
)
df2 <-
data.frame(
x = c("red", "green"),
y = sample(1:100, 20),
z = seq(ymd("2020-01-01"), ymd("2020-01-20"), by = "1 day")
)
df3 <-
data.frame(
x = c("up", "down"),
y = sample(1:100, 20),
z = seq(ymd("2020-01-01"), ymd("2020-01-20"), by = "1 day")
)
dataframes <-
c("df1", "df2", "df3")
exploreDataFrames <- function(dataframes, sequence = seq_along(dataframes)){
for (i in seq_along(sequence)){
print(get(dataframes[i]))
gg <-
get(dataframes[i]) %>%
ggplot(aes(z, y, group = 1)) +
geom_line() +
facet_wrap(~get(names(get(dataframes[i]))[1]))
return(gg)
}
}
exploreDataFrames(dataframes[3])
I'd like for my function to return a list with three entries:
list[1][1] <- name_of_the_dataframe
list[1][2] <- copy_of_the_complete_dataframe
list[1][3] <- ggplot_object
My goal is to be able to have a single list and iterate through the ggplot charts, quickly be able to slice it by the name of a particular data frame and pull up the complete dataframe.
What do I need to change about my function to make this possible?