如何在R中将Transaction对象转换为Dataframe [英] How to convert object of Transaction to Dataframe in R

查看:369
本文介绍了如何在R中将Transaction对象转换为Dataframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将arules包中的数据集(杂货店)转换为数据框.

How to convert the Dataset(Groceries) in arules package to dataframe.

class(Groceries)
[1] "transactions"
attr(,"package")
[1] "arules"

推荐答案

您需要指定实际需要的内容.我没有在arules -package的帮助页面中看到as.data.frame.transactions函数.数据项Groceries确实嵌入了一个数据框,但是看来这是否是您想要的:

You need to specify what is actually needed. I don't see an as.data.frame.transactions function in the help page for the arules-package. The data-item Groceries does have a dataframe embedded in it but whether that is what you want seems unlikely:

str(Groceries)
Formal class 'transactions' [package "arules"] with 3 slots
  ..@ data       :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
  .. .. ..@ i       : int [1:43367] 13 60 69 78 14 29 98 24 15 29 ...
  .. .. ..@ p       : int [1:9836] 0 4 7 8 12 16 21 22 27 28 ...
  .. .. ..@ Dim     : int [1:2] 169 9835
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. .. ..@ factors : list()
  ..@ itemInfo   :'data.frame': 169 obs. of  3 variables:
  .. ..$ labels: chr [1:169] "frankfurter" "sausage" "liver loaf" "ham" ...
  .. ..$ level2: Factor w/ 55 levels "baby food","bags",..: 44 44 44 44 44 44 44 42 42 41 ...
  .. ..$ level1: Factor w/ 10 levels "canned food",..: 6 6 6 6 6 6 6 6 6 6 ...
  ..@ itemsetInfo:'data.frame': 0 obs. of  0 variables

我猜你实际上想要的是

as.matrix( Groceries@data )

可能将Groceries@ itemInfo$ labels添加为行名

这篇关于如何在R中将Transaction对象转换为Dataframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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