Message-ID: <1322217108.760.13.camel@milan>
Date: 2011-11-25T10:31:47Z
From: Milan Bouchet-Valat
Subject: Error: invalid type(list) for variable when using lm()
In-Reply-To: <1322208171670-4106669.post@n4.nabble.com>
Le vendredi 25 novembre 2011 ? 00:02 -0800, Dhaynes a ?crit :
> Hello,
>
> I am new to R.
> I have multidimensional array (379,2,3) and I need to create a series of
> linear regressions (379 to be exact)
> I have the array stored properly I believe, but I can not use the
> lm(myarray[1,1,1:3]~myarray[1,2,1:3])
> I have checked to make sure they are exactly the same length.
> I have also tried endlessly to convert the subset of the array back into a
> vector.
>
> any help would be appreciated.
The 'formula' argument of lm doesn't take actual values, but variable
names. So you need to create vectors containing your data, or pass a
data frame with these vectors are columns. So, going the latter way :
df <- data.frame(a=myarray[1,1,1:3], b=myarray[1,2,1:3])
lm(a ~ b, data=df)
or in one step
lm(a ~ b, data=data.frame(a=myarray[1,1,1:3], b=myarray[1,2,1:3]))
Regards