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, coeffname
1 USA 1.2
2 GB 1.0
3 France 1.1
I tried to do :
do.call("rbind", lapply(allRics[1:5], fitit))
but i don know what to do next.
Can anyone help?
thanks!