使用R将类别“ tbl_df”,“ tbl”和“ data.frame”转换为数据帧 [英] Convert Classes ‘tbl_df’, ‘tbl’ and 'data.frame into dataframe with R

查看:1873
本文介绍了使用R将类别“ tbl_df”,“ tbl”和“ data.frame”转换为数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了以下数据:

> 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中的数据?
是否可以转换为数据帧?

I want to make a plot with ggplot2 but i cant access the data in $segment ? Is it possible to convert into dataframe ?

推荐答案

df = as.data.frame(gaDataExt)

就这么简单。

这篇关于使用R将类别“ tbl_df”,“ tbl”和“ data.frame”转换为数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆