title: lm function in R does not give coefficients for all factor levels in categorical data
body: <p>I was trying out linear regression with R using categorical attributes and observe that I don't get a coefficient value for each of the different factor levels I have. </p>
  
  <p>Please see my code below, I have 5 factor levels for states, but see only 4 values of co-efficients.</p>
  
  <pre><code>&gt; states = c("WA","TE","GE","LA","SF")
  &gt; population = c(0.5,0.2,0.6,0.7,0.9)
  &gt; df = data.frame(states,population)
  &gt; df
    states population
  1     WA   0.5
  2     TE   0.2
  3     GE   0.6
  4     LA   0.7
  5     SF   0.9
  &gt; states=NULL
  &gt; population=NULL
  &gt; lm(formula=population~states,data=df)
  
  Call:
  lm(formula = population ~ states, data = df)
  
  Coefficients:
  (Intercept)     statesLA     statesSF     statesTE     statesWA  
          0.6          0.1          0.3         -0.4         -0.1
  </code></pre>
  
  <p>I also tried with a larger data set by doing the following, but still see the same behavior</p>
  
  <pre><code>for(i in 1:10)
  {
      df = rbind(df,df)
  }
  </code></pre>
  
  <p>EDIT : Thanks to responses from eipi10, MrFlick and economy. I now understand one of the levels is being used as reference level. But when I get a new test data whose state's value is "GE", how do I substitute in the equation y=m1x1+m2x2+...+c ?</p>
  
  <p>I also tried flattening out the data such that each of these factor levels gets it's separate column, but again for one of the column, I get NA as coefficient. If I have a new test data whose state is 'WA', how can I get the 'population value'? What do I substitute as it's coefficient?</p>
  
  <pre><code>&gt; df1
  </code></pre>
  
  <p>population GE MI TE WA
      1     1  0  0  0  1
      2     2  1  0  0  0
      3     2  0  0  1  0
      4     1  0  1  0  0</p>
  
  <blockquote>
    <p>lm(formula = population ~ (GE+MI+TE+WA),data=df1)</p>
  </blockquote>
  
  <pre><code>Call:
  lm(formula = population ~ (GE + MI + TE + WA), data = df1)
  
  Coefficients:
  (Intercept)           GE           MI           TE           WA  
            1            1            0            1           NA  
  </code></pre>