invalid type (list) for variable

tl;dr rows of data frames are lists, not numeric vectors. When you read.table() you get a data frame (so constructing a matrix, as I did before, doesn’t replicate the problem).

data <- as.data.frame(matrix(rnorm(36),nrow=3))
young <- data[1,]; med <- data[2,]; old <- data[3,]
Price <- c(young, med, old)
str(Price)
## ## List of 36
## ##  $ V1 : num 0.648
## ##  $ V2 : num 0.157
## ## ...

The fact that this is a list, not a numeric vector, is a problem. There are a variety of ways of handling this. The easiest is unlist():

dd <- data.frame(Age,Price=unlist(Price))
aov(Price~Age,dd)

Leave a Comment

tech