I have two tibbles and I am trying to apply the glimpse() function to each tibble. It can be done easily using for loops. But I am wondering how to do it using map() or other similar functions.
df1 <- tibble(A = c(1,1,1), B = c(2,2,2))
df2 <- tibble(C = c(3,3,3), D = c(4,4,4))
dfs = list(df1, df2)
I want this:
for (df in dfs) {
glimpse(df)
}
# Rows: 3
# Columns: 2
# $ A <dbl> 1, 1, 1
# $ B <dbl> 2, 2, 2
# Rows: 3
# Columns: 2
# $ C <dbl> 3, 3, 3
# $ D <dbl> 4, 4, 4
But map does this:
map(dfs, glimpse)
# Rows: 3
# Columns: 2
# $ A <dbl> 1, 1, 1
# $ B <dbl> 2, 2, 2
# Rows: 3
# Columns: 2
# $ C <dbl> 3, 3, 3
# $ D <dbl> 4, 4, 4
# [[1]]
# # A tibble: 3 × 2
# A B
# <dbl> <dbl>
# 1 1 2
# 2 1 2
# 3 1 2
#
# [[2]]
# # A tibble: 3 × 2
# C D
# <dbl> <dbl>
# 1 3 4
# 2 3 4
# 3 3 4