R_old_tips4 の変更点 - アールメカブ

アールメカブ


R_old_tips4 の変更点


#author("2019-07-17T09:04:33+09:00","","")
[[R_old_tips3]]



* [[R_64_bit_packages]] [#o1658143]


* biplot のラベルを変える [#e1990575]

 res.pc <- princomp(res, scale = 1)
 rownames(res.pc$loadings) <- c("安部","麻生","福田","鳩山")
 names(res.pc$scale) <- c("安部","麻生","福田","鳩山

* 要素の長さが違うリストからテーブルを作る [#g94cece7]

もっとエレガントな方法(関数)があったような。

 > a <- c("A","A", "B", "A")
 > b <- c("A","B", "C", "A", "B")
 > c <- c("C","A", "C", "B", "A", "B")
 > 
 > abc <- list(a,b,c)
 > names(abc) <- c("あ","い","う")
 > abc
 $あ
 [1] "A" "A" "B" "A"
 
 $い
 [1] "A" "B" "C" "A" "B"
 
 $う
 [1] "C" "A" "C" "B" "A" "B"
 
 > 
 > abc2 <- lapply(abc, table)
 > abc2
 $あ
 
 A B 
 3 1 
 
 $い
 
 A B C 
 2 2 1 
 
 $う
 
 A B C 
 2 2 2 
 
 > abc3 <- lapply(abc2, data.frame)
 > abc3
 $あ
   Var1 Freq
 1    A    3
 2    B    1
 
 $い
   Var1 Freq
 1    A    2
 2    B    2
 3    C    1
 
 $う
   Var1 Freq
 1    A    2
 2    B    2
 3    C    2
 
 > library(reshape)
  要求されたパッケージ plyr をロード中です 
 > melt(abc3)
 Using Var1 as id variables
 Using Var1 as id variables
 Using Var1 as id variables
   Var1 variable value L1
 1    A     Freq     3 あ
 2    B     Freq     1 あ
 3    A     Freq     2 い
 4    B     Freq     2 い
 5    C     Freq     1 い
 6    A     Freq     2 う
 7    B     Freq     2 う
 8    C     Freq     2 う
 
//data.frame(table(stack(abc)))