To spread a data frame within a list, you can use the lapply()
function along with the tidyr
package's spread()
function. Here is an example code block:
main.r544 chars16 lines
In this example, we have a list called list_df
comprised of two data frames with 3 rows and 3 columns each. We then use lapply()
to apply spread()
to each data frame within the list. The key
argument specifies the column in each data frame used to create new columns, and the value
argument specifies the column used to fill these new columns. The resulting list of spread data frames is stored in spread_list
.
gistlibby LogSnag