-1
speed<- c("15","20","30")
factor <- factor(speed, ordered= TRUE, levels = c("15","20","30"))

I'm trying to calculate mean, sum, min of the factor. How do I do it when I used as.numeric()? It's giving the sum as 6, min as 1.

xgord
  • 4,606
  • 6
  • 30
  • 51
  • Because it makes no sense to compute mean, sum, ecc. on factors. As you can read here for `mean` function, it needs a numeric vector and not a factor... https://www.rdocumentation.org/packages/base/versions/3.4.3/topics/mean – Scipione Sarlo Jan 28 '18 at 20:18

1 Answers1

1

The problem is that as.numeric is not doing what you are expecting.

as.numeric(factor)
[1] 1 2 3

The answers that you got are correct for these numbers. But what I think you wanted was:

as.numeric(as.character(factor))
[1] 15 20 30
G5W
  • 36,531
  • 10
  • 47
  • 80