Error: $ operator is invalid for atomic vectors

What does data look like? Without a minimal REPRoducible EXample (reprex) it's hard to say more (A reprex makes it much easier for others to understand your issue and figure out how to help.)

But one way to get this error is when data is only has a single row. That's make data$ps , for example, an atomic vector, generating this error.

data <- data.frame(
  ps = 1,
  ws = 2,
  c3 = 5,
  sp = 3
)
lm.b <- lm(ps ~ ws + sp + ws:sp, data = data)
anova(lm.b, type = "II")
#> Error: $ operator is invalid for atomic vectors

Created on 2020-04-28 by the reprex package (v0.3.0)

1 Like