我想這一功能應用到數據幀列:暗淡(X)的數據幀應用功能時,必須有一個積極的長度
best_recom <- function(x,n=1) {
y <- result2[x,order(-result2[x,])[n]]
inds = which(result2[x,] == y, arr.ind=TRUE)
recom <- names(inds[1])
return(recom)
}
像這樣:
apply(last_visit[,2], 1, best_recom)
但我得到這個錯誤:
dim(X) must have a positive length
我已經嘗試過把它當成一個像這樣的矩陣:
apply(as.matrix(last_visit)[,2],1,recomenda_n_melhor)
但我得到同樣的錯誤。 這些是所使用的數據幀:
RESULT2 - 相似性矩陣 - 這只是一個樣品
X1.0 X1.1 X2.1 X3.1
X1.0 0.0000000 0.5000000 0.3872983 0.3162278
X1.1 0.5000000 0.0000000 0.2581989 0.0000000
X2.1 0.3872983 0.2581989 0.0000000 0.0000000
X3.1 0.3162278 0.0000000 0.0000000 0.0000000
LAST_VISIT
customer cat
1 1 X5.1
2 2 X6.1
3 3 X1.1
4 4 X2.1
你是否檢查'暗淡(as.matrix (LAST_VISIT)[1,2])'? – 2015-02-10 03:13:24