我尝试在 IdeOne 中使用 R使用Dr. Jerry A Smith的 R 代码显示单值分解 (SVD) 教程中的 SVD 结果。IdeOne 链接在这里,这是我运行的:
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 代码以便显示球洞名称和球员姓名?