Error in 1 | country : operations are possible only for numeric, logical or complex types

Hi,

Welcome to the RStudio community!

The problem is that a linear regression model can only work with numeric data and not categorical (it can with logical i.e. 0 - 1). A way around it so convert a categorical variable into a one-hot representation, i.e. one column per value with 0 or 1. Normally the lm() function should be able to do this automatically like so:

lm(Sepal.Length ~ Species + Petal.Width, data = iris)
#> 
#> Call:
#> lm(formula = Sepal.Length ~ Species + Petal.Width, data = iris)
#> 
#> Coefficients:
#>       (Intercept)  Speciesversicolor   Speciesvirginica        Petal.Width  
#>           4.78044           -0.06025           -0.05009            0.91690

Created on 2021-07-09 by the reprex package (v2.0.0)
You can see that the Species variable gets split into n - 1 new inputs

There seems to be an issue with your data preventing this, but it's hard to say without being able to run the code. So I suggest you create a reprex and share that so we can figure this out. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

Hope this helps,
PJ