我是R.的新手。我想在r包中看到数据集的内容。 例如
对于“arules”包。我想查看数据集Adult的内容。
我试过以下代码。但没有工作
library("arules")
data(Adult)
View(Adult)
它不起作用。
以及
data(Adult)
Adult<-as("Adult",matrix)
...
答案 0 :(得分:2)
加载数据(data(Adult)
)后,您只需编写Adult
即可查看整个数据集。如果数据集很大,您还可以编写head(Adult)
或tail(Adult)
来分别查看数据集的10个第一行或最后一行。 summary(Adult)
为您提供数据集的摘要。 str(Adult)
显示结构,即以各种条目存储的格式。
答案 1 :(得分:0)
使用
成人及LT; -as(成人, “基体”)
答案 2 :(得分:0)
数据集Adult是由arules的作者定义的特殊数据集。
> library("arules")
> data(Adult)
> class(Adult)
[1] "transactions"
attr(,"package")
[1] "arules"
> str(Adult)
Formal class 'transactions' [package "arules"] with 4 slots
..@ transactionInfo:'data.frame': 48842 obs. of 1 variable:
.. ..$ transactionID: Factor w/ 48842 levels "1","10","100",..: 1 11112 22223 33334 43288 44399 45510 46621 47732 2 ...
..@ data :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
.. .. ..@ i : int [1:612200] 1 10 25 32 35 50 59 61 63 65 ...
.. .. ..@ p : int [1:48843] 0 13 26 39 52 65 78 91 104 117 ...
.. .. ..@ Dim : int [1:2] 115 48842
.. .. ..@ Dimnames:List of 2
.. .. .. ..$ : NULL
.. .. .. ..$ : NULL
.. .. ..@ factors : list()
..@ itemInfo :'data.frame': 115 obs. of 3 variables:
.. ..$ labels :Class 'AsIs' chr [1:115] "age=Young" "age=Middle-aged" "age=Senior" "age=Old" ...
.. ..$ variables: Factor w/ 13 levels "age","capital-gain",..: 1 1 1 1 13 13 13 13 13 13 ...
.. ..$ levels : Factor w/ 112 levels "10th","11th",..: 111 63 92 69 30 54 65 82 90 91 ...
..@ itemsetInfo :'data.frame': 0 obs. of 0 variables
如果您想查看Adult的内容,可以使用:
> aa <- Adult@data
> class(aa)
[1] "ngCMatrix"
attr(,"package")
[1] "Matrix"
> str(aa)
Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
..@ i : int [1:612200] 1 10 25 32 35 50 59 61 63 65 ...
..@ p : int [1:48843] 0 13 26 39 52 65 78 91 104 117 ...
..@ Dim : int [1:2] 115 48842
..@ Dimnames:List of 2
.. ..$ : NULL
.. ..$ : NULL
..@ factors : list()
> dim(aa)
[1] 115 48842
> aa[1:5,1:5]
5 x 5 sparse Matrix of class "ngCMatrix"
[1,] . . . . .
[2,] | . | . |
[3,] . | . | .
[4,] . . . . .
[5,] . . . . .