R/check_variables_match_across_dfs.R

Defines functions check_variables_match_across_dfs

check_variables_match_across_dfs <- function(df_list) {
  
  # Function to check if the names match the first dataframe
  names_match_first_df <- function(df, first_df_names) {
    all(sort(base::names(df)) == first_df_names)
  }
  
  # Extract and sort the names of the first data frame in df_list
  first_df_names_sorted <- sort(base::names(df_list[[1]]))
  
  # Identify data frames that do not match
  non_matching_dfs <- base::sapply(df_list, names_match_first_df, first_df_names_sorted)
  
  # Get the indices of the data frames with non-matching names
  non_matching_indices <- base::which(!non_matching_dfs)
  
  # Return the indices of non-matching data frames
  non_matching_indices
}

Try the FAST.R package in your browser

Any scripts or data that you put into this service are public.

FAST.R documentation built on June 22, 2024, 6:48 p.m.