0

I have the following dplyr table:

> movies
Source: local data frame [250 x 3]

                                            name   year rating
                                          (fctr) (fctr) (fctr)
1                       The Shawshank Redemption   1994    9.2
2                                  The Godfather   1972    9.2
3                         The Godfather: Part II   1974      9
4                                The Dark Knight   2008    8.9
...

I want to do some basic analysis using summarise. when I enter something like:

summarise(movies,count = sum(rating))

I get:

Error in Summary.factor(c(12L, 12L, 11L, 10L, 10L, 10L, 10L, 10L, 10L,  : 
‘sum’ not meaningful for factors

So - I've been trying to change 'rating' from a factor to a numeric. I've tried

as.numeric(as.character(movies$rating))

and

transform(movies, rating = as.numeric(rating))

But neither seem to work. I'm sure I'm missing something very basic. Do I need to change the factor to an integer? I'm assuming I do. How can I get this done?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Windstorm1981
  • 2,564
  • 7
  • 29
  • 57

0 Answers0