Displaying 1 result from an estimated 1 matches for "lm_f".
Did you mean:
ll_f
2011 Oct 24
1
Creating data frame with residuals of a data frame
...his data frame from the resulting list
since the list has differing numbers of rows.
So for example:
age<- c(5,6,10,14,16,NA,18)
value1<- c(30,70,40,50,NA,NA,NA)
value2<- c(2,4,1,4,4,4,4)
df<- data.frame(age, value1, value2)
#Run linear regression to adjust for age and get residuals:
lm_f <- function(x) {
x<- residuals(lm(data=df, formula= x ~ age))
}
resid <- apply(df,2,lm_f)
resid<- resid[-1]
Then resid is a list with different row numbers:
$value1
1 2 3 4
-16.945813 22.906404 -7.684729 1.724138
$value2
1 2...