Factor with 2 levels, but R Studio only sees 1

All my dummy variables are "Factor w/2 levels "0", "1"", but when I run ModelHK <- VAR(HK, p = 2, type = "const", season = 6), I keep getting the error that all my factors needs 2 or more levels.

Does anyone know how I can solve this?

Thanks!

Hi Thies,
I have two suggestions.

  1. confirm your data's factor levels by peeking at your df with str(df)
  2. can you tell us what package the 'VAR' function you are using is from? this would allow us to experiment with it ourselves.

Regards.
Nir

not necessarily if it also shows 2' where you see the 1s in the dataframe. That would be expected for factors.

Would consider running the str code and sharing as requested?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Hi Nir,

Thanks for you reply.

The package I use is "vars".
So the dummies only contain 0s and 1s, and I noticed that when I change them from number to factor using the as.factor function, the environment only shows 1s where I see 0s in my dataframe. Could it be that this is where it goes wrong?

Thanks!