Search code examples
rdataframeshinysummarydatalist

Create a table with count of columns, count of rows, count of NA in row , out of dataframes in a list


I am refreshing my knowledge of R... and I am struggling :) I really need your help. What I want to do is to create a data table like that:

data source name | nrow | ncol | count if NA
data source1 | 23 | 3 | 2
data source2 | 2 | 21 | na
data source3.... and so on.

Data sources are data frames nested in a list. What I did so far:

columns <- lapply(list, length) 
rows <-sapply(list,nrow)

when I am trying to merge these two - impossible. Also do not know how to get the NA from rows.

the sample of the data is in the list and it looks like this:

list: data source1 : column1: run1; column2: run2; column3: run3....; data source2: column1: net; column2: gross;.... How can I create a simple table with the outlook I am looking for? should I run it through the loop?


Solution

  • library(purrr)
    
    df_list %>% 
      imap_dfr(~c(source = .y, nrow = nrow(.x), ncol = ncol(.x), NA_count = sum(is.na(.x))))
    

    you can use this if df_list has names. If it doesnt then assign names to it:

    names(df_list) <- source_vec
    

    where source_vec is mapping source to data frames in df_list