I want to make the following case of linear regression in R
year<-rep(2008:2010,each=4)
quarter<-rep(1:4,3)
cpi<-c(162.2,164.6,166.5,166.0,166.4,167
The error lies in the way you're data was formatted. Here is another option:
year<-seq(from=2008,to=2010.75,by=.25)
cpi<-c(162.2,164.6,166.5,166.0,166.4,167.0,168.6,169.5,170.0,172.0,173.3,174.0)
df <- data.frame(year,cpi)
plot(df)+abline(lm(df$cpi~df$year))
Then you can reformat the axes labels if you like.