Re: [R] Regression by factor using "sapply"

2011-08-25 Thread Paul Hiemstra
I would take a look at the ddply function from the plyr package. Without a reproducible example (most importantly an example dataset) I cannot give you some example code. cheers, Paul On 08/24/2011 05:51 PM, elh wrote: > Apologies for the elementary nature of the question (yes, I'm another > new

Re: [R] Regression by factor using "sapply"

2011-08-24 Thread Jorge I Velez
Hi elh, You could try using split() and lapply() instead (untested): mymodels <- lapply(split(usage, ActNo), function(l) lm(AvgKWh ~ AvgHDD + AvgCDD, data = l) ) To access the coefficients for all models you can do lapply(mymodels, coef) and, to access model number one (first ActNo), mymodels

[R] Regression by factor using "sapply"

2011-08-24 Thread elh
Apologies for the elementary nature of the question (yes, I'm another newbie)... I'd like to perform a multiple regression on a single data set containing a representation of energy consumption and temperatures containing account number, usage (KWh), heating degree days (HDD) and cooling degree (C