0

I'm new to R and trying to do a simple ANOVA. I created a data frame:

MeanTable <- data.frame(Age=c("2","2","2","4","4","4","6","6","6"), 
   Yield=c("12.812","15.17","13.868","24.456","23.444","25.312",
         "21.146","21.63","21.84"),stringsAsFactors = FALSE)

And then tried to do an ANOVA, but I got this warning message:

Warning messages: 1: In mean.default(X[[i]], ...) : argument is not numeric or logical: returning NA 2: In mean.default(X[[i]], ...) : argument is not numeric or logical: returning NA 3: In mean.default(X[[i]], ...) : argument is not numeric or logical: returning NA

So I assume that means I'm meant to use as.numeric to convert the values from factors into numbers. So I did this:

as.numeric(MeanTable$Age)
is.numeric(MeanTable$Age)

But got FALSE. What am I doing wrong? Or is my issue something else entirely?

1
  • 2
    why are you putting quotes around everything? or is that how the data come to you? To brute-force it, you can add MeanTable[] <- lapply(MeanTable, type.convert) but this can be avoided by not doing the quotes Commented Apr 3, 2016 at 19:09

1 Answer 1

3

You need to change the response value to numeric within the data frame.

MeanTable <- data.frame(Age=c("2","2","2","4","4","4","6","6","6"), 
   Yield=c("12.812","15.17","13.868","24.456","23.444","25.312",
         "21.146","21.63","21.84"),stringsAsFactors = FALSE)

MeanTable$Yield <- as.numeric(MeanTable$Yield)
lm(Yield~Age,data=MeanTable)

As @rawr points out it would be easier if your variables were numeric to begin with. However, be careful: if you make Age numeric rather than categorical you will be fitting a regression model rather than a 1-way ANOVA.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.