r - 使用 R 将类 ‘tbl_df’ 、 ‘tbl’ 和 'data.frame 转换为数据帧

标签 r dplyr

我得到了这些数据:

> str(gaDataExt)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   2 obs. of  5 variables:
 $ date          : POSIXct, format: "2016-05-24" "2016-05-31"
 $ deviceCategory: chr  "desktop" "desktop"
  $ users         : int  1 2
  $ sessions      : int  1 2
  $ pageviews     : int  11 85
  - attr(*, "profileInfo")=List of 6
   ..$ profileId            : chr "25439551"
   ..$ accountId            : chr "12543305"
   ..$ webPropertyId        : chr "UA-12543305-1"
   ..$ internalWebPropertyId: chr "26790206"
   ..$ profileName          : chr "www.ciao.ch"
   ..$ tableId              : chr "ga:25439551"
  - attr(*, "query")=List of 8
   ..$ start.date : chr "30daysAgo"
   ..$ end.date   : chr "yesterday"
   ..$ profileId  : chr "ga:25439551"
   ..$ dimensions : chr "ga:date,ga:deviceCategory"
   ..$ metrics    : chr  "ga:users" "ga:sessions" "ga:pageviews"
   ..$ segment    : chr "sessions::condition::ga:pagePath=@/f            /relations     /questions_reponses-best_of/;sessions::condition::ga:pagePath=@/f/manger-bouger/q"| __truncated__

   ..$ start.index: int 1
   ..$ max.results: int 10000
  - attr(*, "sampled")= logi FALSE

我想用 ggplot2 画图,但无法访问 $segment 中的数据? 是否可以转换为数据框?

最佳答案

df = as.data.frame(gaDataExt)

就这么简单。

关于r - 使用 R 将类 ‘tbl_df’ 、 ‘tbl’ 和 'data.frame 转换为数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594411/

相关文章:

r - 始终将 ggplot 标题放在面板而不是绘图上

r - 根据 "group"大小更改矢量的编号

r - 用日期的最大值在 dplyr 中汇总 - R

r - 在 dplyr 中按向量划分选定的列

r - 有没有办法使用 rowSums 和 is.numeric 只对数字列求和?

r - 创建具有可变尺寸的嵌套数据框

r - 这是 group_by 和 lead/lag 中的错误吗?

r - 裁剪和 mask 光栅堆栈的并行处理速度较慢

r - data.table根据条件更新组中的最后一个元素

r - 手动使用 R Knit/Markdown 生成 HTML 绘图