Hi gurus,

I have a big data frame df, with columns named as :

age, income, country

what I want to do is very simpe actually, do

fitFunc<-function(thisCountry){
    subframe<-df[which(country==thisCountry),];
    fit<-lm(income~0+age, data=subframe);
    return(coef(fit));}

for each individual country. Then aggregate the result into a new data
frame looks like :

    countryname,  coeffname1      USA         1.22      GB
1.03      France      1.1

I tried to do :
do.call("rbind", lapply(countries, fitFunc))

but this only gives something like:

          age
[1,] 2.540879
[2,] 2.428830
[3,] 2.369560
How should I proceed?

can anyone help?


-- 
*CHEN*, Cheng

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to