【发布时间】:2018-06-09 23:49:24
【问题描述】:
我有以下看起来像这样的数据框(3 列作为列表)。
A tibble: 14 x 4
clinic_name drop_in_hours appointment_hours services
<chr> <list> <list> <list>
1 Birth Control and Sexual Health Centre <list [1]> <list [1]> <list [1]>
2 Black Creek Community Health Centre (Sheridan Mall Site) <list [1]> <list [1]> <list [1]>
3 Black Creek Community Health Centre (Yorkgate mall Site) <list [1]> <list [1]> <list [1]>
4 Crossways Clinic <list [1]> <list [1]> <list [1]>
5 Hassle Free Clinic <list [1]> <list [1]> <list [1]>
6 Immigrant Women's Health Center <list [1]> <list [1]> <list [1]>
7 Rexdale Community Health Center <list [1]> <list [1]> <list [1]>
8 Rexdale Youth Resource Center <list [1]> <list [1]> <list [1]>
9 Scarborough Sexual Health Clinic <list [1]> <list [1]> <list [1]>
10 Special Treatment Clinic <list [1]> <list [1]> <list [1]>
11 Taibu Community Health Center <list [1]> <list [1]> <list [1]>
12 The Gate <list [1]> <list [1]> <list [1]>
13 The Jane Street Clinic <list [1]> <list [1]> <list [1]>
14 The Talk Shop <list [1]> <list [1]> <list [1]>
我想将其输出为 csv 文件。我注意到数据框的列不应该是 R 中的列表。所以我做了一些谷歌并找到了这个 save data.frames with list-column 所以我试了一下:
library(tidyverse)
df %>%
mutate(drop_in_hours = map_chr(drop_in_hours, ~ capture.output(dput(.))),
appointment_hours = map_chr(appointment_hours, ~ capture.output(dput(.))),
services = map_chr(services, ~ capture.output(dput(.))) ) %>%
write_csv("health.csv")
但是我遇到了一个错误,我在这里遗漏了什么吗?
Error in mutate_impl(.data, dots) :
Evaluation error: Result 4 is not a length 1 atomic vector
.
【问题讨论】:
-
我想你没有将你的
df转换成一个小标题,就像你提到的链接中所示的那样。 -
不,这是一个小标题
-
是否要在 CSV 文件中展开列表项?
-
@Cybernetic 我有一个观察列表
-
请看我的回答。