如何显示Golf SVD示例的行名和列名?

时间:2013-05-02 03:57:51

标签: r svd

我尝试在IdeOne中使用R来使用Single Value Decomposition (SVD) tutorial中的R代码显示Dr. Jerry A Smith的SVD结果。 IdeOne链接是here,这是我运行的内容:

scores<-c(4,4,3,4,4,3,4,2,5,4,5,3,5,4,5,4,4,5,5,5,2,4,4,4,3,4,5)
golfMatrix<-matrix(scores,nrow=9)
rownames(golfMatrix)<-c("Hole 1", "Hole 2", "Hole 3", "Hole 4", "Hole 5", "Hole 6", "Hole 7", "Hole 8", "Hole 9")
colnames(golfMatrix)<-c("Phil", "Tiger", "Vijay")
print (golfMatrix)
golfSVD<-svd(golfMatrix, nu=nrow(golfMatrix), nv=ncol(golfMatrix))
golfSVD
approx_Golf_1 <- golfSVD$u[,1] %*% t(golfSVD$v[,1]) * golfSVD$d[1]
print (approx_Golf_1)

我得到底线的结果没有像杰里·史密斯博士那样的洞和球员名字的例子:

[,1]     [,2]     [,3]
 [1,] 3.954119 4.649399 4.347188
 [2,] 4.281532 5.034384 4.707149
 [3,] 2.429859 2.857118 2.671405
 [4,] 3.975401 4.674423 4.370586
 [5,] 3.647987 4.289438 4.010625
 [6,] 3.696949 4.347010 4.064454
 [7,] 3.341855 3.929477 3.674061
 [8,] 3.091084 3.634611 3.398361
 [9,] 4.559984 5.361798 5.013281

如何修改R代码,以便显示孔名称&amp;球员名字?

0 个答案:

没有答案