2017-02-11 12 views
1

私は以下のようなデータフレーム/ティブルを持っています。分割リストの列を複数の行に分割[R]

# # 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の語彙は現時点で私を失望させています。

これについてのご支援をいただければ幸いです。

私の転倒の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")) 

答えて

2

我々は速かったunnest

library(tidyverse) 
unnest(df) 
+1

を使用することができます!私は今受け入れている答えを受け入れるだろうが、私を許さないだろう。私はそれが語彙の問題であることを知っていました。 – Dan

+0

@Dan 'reshape2'からの' melt'と 'tidyr'からの' gather'は 'wide'フォーマットから 'long'フォーマットへの変換に使われ、 'list'カラムには触れません。 – akrun

+1

ええ、私は彼らがそれをしたことを知っていた、私はちょうど列の間でリストが分割されるいくつかの種類の機能が必要かもしれないと思った。明らかに 'unnest()'は簡単にそれを行います。 – Dan

関連する問題