Save a data frame with list-columns as csv file

前端 未结 5 760
清歌不尽
清歌不尽 2021-02-09 06:01

I have the following data frame that looks like this (3 columns as list).

A tibble: 14 x 4
                                                    clinic_name drop_         


        
5条回答
  •  太阳男子
    2021-02-09 06:34

    Here's another option that may be a little simpler.

    Depending on the data, comma separated values could get complicated, so I'm using a bar | for separating values in list columns:

    library(tidyverse)
    
    starwars %>% 
      rowwise() %>% 
      mutate_if(is.list, ~paste(unlist(.), collapse = '|')) %>% 
      write.csv('df_starwars.csv', row.names = FALSE)
    

    starwars is one of the dplyr sample dataframes.

提交回复
热议问题