gpt4 book ai didi

r - 将列表列拆分为多行

转载 作者:行者123 更新时间:2023-12-05 04:11:43 25 4
gpt4 key购买 nike

<分区>

我有一个如下所示的数据框/tibble。

# # A tibble: 2 × 3
# from_id created_time text
# <chr> <chr> <list>
# 1 10113538711 2017-02-10T23:33:01+0000 <chr [3]>
# 2 10113538711 2017-02-10T05:41:39+0000 <chr [5]>

我想将文本列中的 list 项目散布到各行中,如下所示。

# # A tibble: 2 × 3
# from_id created_time text
# <chr> <chr> <chr>
# 1 10113538711 2017-02-10T23:33:01+0000 "earlier this week we received ..."
# 1 10113538711 2017-02-10T23:33:01+0000 "lance payne's photo struck a c..."
# 1 10113538711 2017-02-10T23:33:01+0000 "this is his story:"
# 2 10113538711 2017-02-10T05:41:39+0000 "i'm melting, but extreme heat ..."
# 2 10113538711 2017-02-10T05:41:39+0000 "place the container in an area..."
# 2 10113538711 2017-02-10T05:41:39+0000 "please share far and wide."
# 2 10113538711 2017-02-10T05:41:39+0000 "thank you."
# 2 10113538711 2017-02-10T05:41:39+0000 "photo © tanya-dee johnson"

我想尝试 tidy::separate() 但在我的使用中不起作用。我怀疑这是某种形式的拆分或分离,然后是 gather()melt(),但目前我的 R 词汇让我失望。

如有任何帮助,我们将不胜感激。

我的 tibble 的 DPUT。

> dput(df)

structure(list(from_id = c("10113538711", "10113538711"), created_time = c("2017-02-10T23:33:01+0000",
"2017-02-10T05:41:39+0000"), text = structure(list(c("earlier this week we received shocking photos of a turtle hatchling emerging beside a lump of coal at mackay's east point beach near hay point – the largest coal port alongside the great barrier reef.",
"lance payne's photo struck a chord around the country.", "this is his story:"
), c("i'm melting, but extreme heat causes significant stress particularly for all animals.",
"place the container in an area where animals are protected from predators when drinking eg near a shrub or bush and keep your pets away from this area so that animals can drink undisturbed.",
"please share far and wide.", "thank you.", "photo © tanya-dee johnson"
)), class = c("get_sentences", "list"))), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -2L), .Names = c("from_id",
"created_time", "text"))

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com