0

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"

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Ching
  • 135
  • 1
  • 9
  • So, R can't find the function `spread`. Is it the one in `tidyr`? – kangaroo_cliff Sep 11 '17 at 03:07
  • @DiscoSuperfly find it in tidyverse – Ching Sep 11 '17 at 03:24
  • 2
    @Ching `tidyverse` is a collection of packages. One of the package is `tidyr`, and `spread` is from `tidyr`. As a result, load the `tidyr` package is likely to solve your question, too. Type `?spread` and see the documentation and you can see it is from the `tidyr` package. Next time, if R cannot find certain functions, it would be great if you can google the function name to see the origin of this function. – www Sep 11 '17 at 05:14

1 Answers1

4

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.

markdly
  • 4,394
  • 2
  • 19
  • 27