Rで解析:list classの構造把握に便利です「listless」パッケージ

list classの構造把握に便利なパッケージの紹介です。とっても便利だと考えます。listは便利なclassだけれども、構造を把握するのが面倒なのでお勧めなパッケージです。

パッケージバージョンは0.0-2。windows 10のR version 3.3.2で動作を確認しています。

パッケージのインストール

下記コマンドを実行してください。

#パッケージのインストール
install.packages("listless")

コマンドの紹介

詳細はコマンド、各パッケージのヘルプを確認してください。

#パッケージの読み込み
library("listless")

###データ例の作成#####
TestList <- list(a = list(1:5), b = list(sb1 = 1, sb2 = list(5:3, 14:20)),
                 C = matrix(1:10, 2), D = LETTERS[1:6])
#&#30906;&#35469;
#&#28145;&#12373;&#12364;3&#12398;&#12522;&#12473;&#12488;
str(TestList)
List of 4
$ a:List of 1
..$ : int [1:5] 1 2 3 4 5
$ b:List of 2
..$ sb1: num 1
..$ sb2:List of 2
.. ..$ : int [1:3] 5 4 3
.. ..$ : int [1:7] 14 15 16 17 18 19 20
$ C: int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10
$ D: chr [1:6] "A" "B" "C" "D" ...
########

#&#12522;&#12473;&#12488;&#12398;&#28145;&#12373;&#12434;&#34920;&#31034;:list_depth&#12467;&#12510;&#12531;&#12489;
list_depth(TestList)
[1] 3

#&#12522;&#12473;&#12488;&#12398;&#25104;&#20998;&#21517;&#12392;&#27083;&#36896;&#12434;&#34920;&#31034;:list_str&#12467;&#12510;&#12531;&#12489;
list_str(TestList)
names names.1 names.2     class      mode length dims
1     a    &lt;NA&gt;    &lt;NA&gt;   integer   numeric      5
2     b     sb1    &lt;NA&gt;   numeric   numeric      1
3     b    sb21    &lt;NA&gt;   integer   numeric      3
4     b    sb22    &lt;NA&gt;   integer   numeric      7
5     C    &lt;NA&gt;    &lt;NA&gt;    matrix   numeric     10 2, 5
6     D    &lt;NA&gt;    &lt;NA&gt; character character      6

#&#12522;&#12473;&#12488;&#27083;&#36896;&#12434;data.frame&#12391;&#34920;&#31034;:list_to_data.frame&#12467;&#12510;&#12531;&#12489;
list_to_data.frame(TestList)
names names.1 names.2 values
1      a            &lt;NA&gt;      1
2      a            &lt;NA&gt;      2
3      a            &lt;NA&gt;      3
4      a            &lt;NA&gt;      4
5      a            &lt;NA&gt;      5
6      b     sb1    &lt;NA&gt;      1
7      b     sb2              5
8      b     sb2              4
9      b     sb2              3
10     b     sb2             14
11     b     sb2             15
12     b     sb2             16
13     b     sb2             17
14     b     sb2             18
15     b     sb2             19
16     b     sb2             20
17     C    &lt;NA&gt;    &lt;NA&gt;      1
18     C    &lt;NA&gt;    &lt;NA&gt;      2
19     C    &lt;NA&gt;    &lt;NA&gt;      3
20     C    &lt;NA&gt;    &lt;NA&gt;      4
21     C    &lt;NA&gt;    &lt;NA&gt;      5
22     C    &lt;NA&gt;    &lt;NA&gt;      6
23     C    &lt;NA&gt;    &lt;NA&gt;      7
24     C    &lt;NA&gt;    &lt;NA&gt;      8
25     C    &lt;NA&gt;    &lt;NA&gt;      9
26     C    &lt;NA&gt;    &lt;NA&gt;     10
27     D    &lt;NA&gt;    &lt;NA&gt;      A
28     D    &lt;NA&gt;    &lt;NA&gt;      B
29     D    &lt;NA&gt;    &lt;NA&gt;      C
30     D    &lt;NA&gt;    &lt;NA&gt;      D
31     D    &lt;NA&gt;    &lt;NA&gt;      E
32     D    &lt;NA&gt;    &lt;NA&gt;      F

少しでも、あなたの解析が楽になりますように!!

Prices and shipping availability may change. Please refer to the product page at time of purchase.
Content displayed on this site is provided by Amazon and may be updated or removed.
Amazon Associate, This site earns income through qualifying sales.
タイトルとURLをコピーしました