You can transform a list into a dataframe in long form in R using the enframe() function from the tibble package in combination with unnest() from the tidyr package, or by using the stack() function. Here's an example of how to do it:
main.r472 chars24 lines
In all the above examples, my_list is the input list and my_df is the output dataframe in long form. The key column represents the names of the elements in the list, and the value column represents the values of the elements.
Note that the enframe() function returns a dataframe with a column named name and a column named value, so we need to rename name to key to match the desired output. The stack() function also returns a dataframe with columns named values and ind, so we can simply assign the result to my_df. The data.frame() method requires us to create the key column manually using rep() and the value column using unlist().
gistlibby LogSnag