我正在尝试将此函数应用于数据帧列:
就像这样:
我正在尝试将此函数应用于数据帧列:
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
上次访问时间
customer cat
1 1 X5.1
2 2 X6.1
3 3 X1.1
4 4 X2.1
dim(as.matrix(last_visit)[,2])
吗? - user3710546