I work with a large number of dataframes in R and I want to find the dataframes with the minimum and the maximum number of columns and finding the difference in their column names. However, I got stuck in turning my map_dbl results to a regular tibble.
first_df = data.frame(matrix(rnorm(20), nrow=10))
second_df = data.frame(matrix(rnorm(20), nrow=4))
third_df = data.frame(matrix(rnorm(20), nrow=5))
library(dplyr)
library(purrr)
library(tibble)
library(tidyr)
# capturing all the data frames
mget(ls(pattern = "_df")) %>%
map_dbl(ncol) %>%
as_tibble()
# expected output
# first_df 2
# second_df 5
## Finding the difference in columns
diff <- setdiff(colnames(first_df), colnames(second_df ))