-5

This is the line,

colMeans3 <- colMeans(grade3, na.rm=TRUE)

and R says

Error in colMeans(grades3, na.rm = TRUE) : 'x' must be numeric
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
user3070751
  • 9
  • 3
  • 7
  • Please read http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – nico Jan 11 '14 at 13:26

1 Answers1

2

Subset grade3 to include only numeric variables.

grade3 <- data.frame(a = runif(10), b = rnorm(10), c = letters[1:10])
colMeans(grade3)

find.numeric <- sapply(grade3, is.numeric)
colMeans(grade3[, find.numeric])
        a         b 
0.4675017 0.1642704
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • what if one of the values in the data set is ? the column with as a value was not included in the result. – user3070751 Jan 11 '14 at 10:02
  • `` indicates you have factors in your data set. If you believe they are numeric, you can convert them to using `as.numeric(as.character(x))`, otherwise you have to exclude them from `colMeans` function. – Roman Luštrik Jan 11 '14 at 10:53