I am trying to run an anova model in R. I have a data file which contains 3 rows and 12 columns. Each row is data for a particular level of the explanatory variable. Cell [i,j] is the j'th response for level i. The file is ".dat" extension. I am running the following R code to try to get a 36 by 2 data frame to run the anova model instead of the 3 by 12 original data frame:
data <- read.table("usedcar.dat", row.names = 1)
young <- data[1,]
med <- data[2,]
old <- data[3,]
Price <- c(young, med, old)
Age <- as.factor(c(rep(1,12), rep(2,12), rep(3,12)))
data <- cbind(Age, Price)
data <- as.data.frame(data)
But when I try to get the anova model out of it I get the invalid list type error:
m1 <- aov(Price ~ Age, data = data)
Error in model.frame.default(formula = Price ~ Age, data = data, drop.unused.levels = TRUE) : invalid type (list) for variable 'Price'
What am I doing wrong here?
Here's a random matrix if that will help:
replicate(12, rnorm(3))
Here is the str(data) result:
str(data)
'data.frame': 36 obs. of 2 variables:
$ Age :List of 36
..$ 1 : int 1
..$ 2 : int 1
..$ 3 : int 1
...
..$ 36: int 3
$ Price:List of 36
..$ 1 : int 2300
...
..$ 36: int 2075
data
parameter to a model, you shouldn't subset ($
) in the formula:aov(Price ~ Age, data = data)
– Erkstr(data)
; your chopping seems to have leftPrice
as a list column. – Erkcbind/as.data.frame
, usedata <- data.frame(Age, Price)
. – Fortunetelling