我在用R做矩阵乘法.我已经成功地创建并运行了矩阵Matrix1
,但在try 乘法时发现了一个错误:
Matrix1 = new("markovchain", states = c("state 1", "state 2", "state 3"),
transitionMatrix = matrix(data = c(0,1,0,
0.7,0,0.3,
0.5, 0, 0.5),
byrow = TRUE, nrow = 3),
name = "Matrix Name")
Matrix1
TwoStep = Matrix1%*%Matrix1
TwoStep
我发现Matrix1是S4
型的.我试着用as.matrix
把它转换成S4
到矢量,但它没有工作:
> as.matrix(Matrix1)
Error in as.vector(data) :
no method for coercing this S4 class to a vector