找不到功能“传播" [英] could not find function "spread"
问题描述
因此,目前我正试图找出如何从MovieLense( https://grouplens.org/datasets/movielens/100k/).我从教程中阅读了一些说明.
So at the moment I am trying to figure out how to build a movie recommender system from MovieLense (https://grouplens.org/datasets/movielens/100k/). I read some instructions from a tutorial.
library(dplyr)
library(recommenderlab)
library(magrittr)
data <- read.table("u.data", header = F, stringsAsFactors = T)
head(data)
V1 V2 V3 V4
1 196 242 3 881250949
2 186 302 3 891717742
3 22 377 1 878887116
4 244 51 2 880606923
5 166 346 1 886397596
6 298 474 4 884182806
说明:V1
是用户ID,V2
是商品ID,V3
是等级
Explanation: V1
is userid, V2
is itemid, V3
is rating
现在我需要将格式记录到ratingMatrix,结果将是这样的:
Now I need to log format to ratingMatrix, and the result will be like this:
1 2 3 4 5 6 7 8 9 10
1 5 3 4 3 3 5 4 1 5 3
2 4 NA NA NA NA NA NA NA NA 2
3 NA NA NA NA NA NA NA NA NA NA
4 NA NA NA NA NA NA NA NA NA NA
5 4 3 NA NA NA NA NA NA NA NA
6 4 NA NA NA NA NA 2 4 4 NA
7 NA NA NA 5 NA NA 5 5 5 4
8 NA NA NA NA NA NA 3 NA NA NA
9 NA NA NA NA NA 5 4 NA NA NA
10 4 NA NA 4 NA NA 4 NA 4 NA
代码:
temp = data %>% select(1:3) %>% spread(V2,V3) %>% select(-1)
temp[1:10,1:10]
spread(.,V2,V3)错误:找不到函数"spread"
Error in spread(., V2, V3) : could not find function "spread"
推荐答案
尝试将library(dplyr)
替换为library(tidyverse)
. spread
函数现在位于tidyr
软件包中,该软件包与dplyr
一起是tidyverse
的一部分.
Try replacing library(dplyr)
with library(tidyverse)
. The spread
function now lives in the tidyr
package which is part of the tidyverse
along with dplyr
.
这篇关于找不到功能“传播"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!