If a and b are data frames, and you want to regress the individual values in a on the values in b, then you need to convert them to vectors. eg:
> lm(as.vector(as.matrix(a))~as.vector(as.matrix(b)))
Call:
lm(formula = as.vector(as.matrix(a)) ~ as.vector(as.matrix(b)))
Coefficients:
(Intercept) as.vector(as.matrix(b))
8.418239 -0.005241
Missing data is by default dropped - see help(lm) and the na.action parameter. The summary method on an lm object will tell you about dropped observations.
Of course ignoring the spatial correlation likely to be present in spatial data will mean your inferences from the parameter estimates will be quite wrong. Map the residuals. And read a good book on spatial stats...
[Edit: oh, and the data frames have to be all numbers or the whole lot gets converted to characters and then... well, who knows...]
Edit:
Another way of getting vectors from data frames is just to use 'unlist':
> a=data.frame(matrix(runif(16),4,4))
> b=data.frame(matrix(runif(16),4,4))
> lm(a~b)
Error in model.frame.default(formula = a ~ b, drop.unused.levels = TRUE) :
invalid type (list) for variable 'a'
> lm(unlist(a)~unlist(b))
Call:
lm(formula = unlist(a) ~ unlist(b))
Coefficients:
(Intercept) unlist(b)
0.6488 -0.3137
I've not seen data.matrix before, thx Gavin.