从 Reddit 中提取的内容工作正常但无法另存为 excel 文件
Extract from Reddit works fine but cannot save as excel file
我正在使用 pushshiftr
提取 Reddit 帖子并且工作正常
install.packages("devtools")
devtools::install_github("whereofonecannotspeak/pushshiftr")
library(pushshiftr)
p<-ps_search_submissions(NA, subreddit = "disability", after = "2019-12-26", before = "2019-12-27")
从这里开始:
https://github.com/dashstander/pushshiftr
在 p 现在我有帖子但是当我尝试使用这个
保存到 excel
write_xlsx(p, "C:/Users/Reddit/posts.xlsx")
我收到错误:
Argument x must be a data frame or list of data frames
本例中的参数是一个列表,但找不到如何导出到 excel
如果我们需要一个数据集,
library(purrr)
out <- map_dfr(p,
~ .x[c('author', 'body', 'created_utc', 'score')] %>% stack, .id = 'grp')
或 base R
out <- type.convert(as.data.frame(do.call(rbind,
lapply(p, function(x) do.call(c, x[c('author', 'body',
'created_utc', 'score')])))), as.is = TRUE)
我正在使用 pushshiftr
提取 Reddit 帖子并且工作正常
install.packages("devtools")
devtools::install_github("whereofonecannotspeak/pushshiftr")
library(pushshiftr)
p<-ps_search_submissions(NA, subreddit = "disability", after = "2019-12-26", before = "2019-12-27")
从这里开始:
https://github.com/dashstander/pushshiftr
在 p 现在我有帖子但是当我尝试使用这个
保存到 excelwrite_xlsx(p, "C:/Users/Reddit/posts.xlsx")
我收到错误:
Argument x must be a data frame or list of data frames
本例中的参数是一个列表,但找不到如何导出到 excel
如果我们需要一个数据集,
library(purrr)
out <- map_dfr(p,
~ .x[c('author', 'body', 'created_utc', 'score')] %>% stack, .id = 'grp')
或 base R
out <- type.convert(as.data.frame(do.call(rbind,
lapply(p, function(x) do.call(c, x[c('author', 'body',
'created_utc', 'score')])))), as.is = TRUE)