将dataframe转换为r中的整洁格式
我有一个具有如下结构的数据框架
> ls.str(df)
attachments : 'data.frame': 1103947 obs. of 2 variables:
$ media_keys:List of 1103947
$ poll_ids :List of 1103947
author_id : chr [1:1103947] "21572351" "21572351" "21572351" "21572351" "21572351" "21572351" "21572351" "21572351" "21572351" "21572351" ...
conversation_id : chr [1:1103947] "1006266341341519872" "1006265425791987715" "1006251577747869696" "1006246236171722753" "1006246168991600642" ...
created_at : chr [1:1103947] "2018-06-11T20:06:05.000Z" "2018-06-11T20:02:27.000Z" "2018-06-11T19:07:26.000Z" "2018-06-11T18:46:12.000Z" ...
entities : 'data.frame': 1103947 obs. of 5 variables:
$ mentions :List of 1103947
$ annotations:List of 1103947
$ hashtags :List of 1103947
$ urls :List of 1103947
$ cashtags :List of 1103947
geo : 'data.frame': 1103947 obs. of 2 variables:
$ place_id : chr NA NA NA NA ...
$ coordinates:'data.frame': 1103947 obs. of 2 variables:
id : chr [1:1103947] "1006266341341519872" "1006265425791987715" "1006251577747869696" "1006246236171722753" "1006246168991600642" ...
in_reply_to_user_id : chr [1:1103947] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA ...
,我想将其转换为整洁的格式。我不知道有什么巧妙的功能要做吗? Google并没有多大帮助。提前致谢!
通过整洁的格式,我的意思是这样:
#> # A tibble: 25 × 31
#> tweet_id user_username text conversation_id author_id lang created_at
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 1406007405180… Phardiga "RT … 14060074051803… 58755490 de 2021-06-1…
#> 2 1405617386405… dorothee_goe… "RT … 14056173864058… 97759337… de 2021-06-1…
#> 3 1405616047990… dejools "RT … 14056160479909… 13065071… de 2021-06-1…
#> 4 1405615055555… LenaOetzel "RT … 14056150555557… 97897581… de 2021-06-1…
#> 5 1405613064968… jenniferhenk… "RT … 14056130649684… 114774406 de 2021-06-1…
#> 6 1405610724026… Tobias_Schul… "Ihr… 14056107240266… 47919307 de 2021-06-1…
#> 7 1405393033558… HTMIBerlin "
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Tidyr
,我们可以用打开包装
(将data.frame列拆卸为常规列),然后使用unnest
转换列表
列到常规列- 输出
数据
With
tidyr
, we could wrap withunpack
(to unpack the data.frame columns into regular columns) and then withunnest
to convert thelist
columns to regular columns-output
data