我有一个数据框,它看起来像这样(作为列表的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中不应该是列表。因此,我做了一些谷歌搜索,并找到了这个使用列表列保存数据框,所以我试了一下:
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
转换为 tibble。 - Scipione Sarlo