could not find function “spread” [closed]

情到浓时终转凉″ 提交于 2019-12-11 16:35:13

问题


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

Explanation: V1 is userid, V2 is itemid, V3 is rating

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

code:

temp = data %>% select(1:3) %>% spread(V2,V3) %>% select(-1)
temp[1:10,1:10]

Error in spread(., V2, V3) : could not find function "spread"


回答1:


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.



来源:https://stackoverflow.com/questions/46147632/could-not-find-function-spread

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!