Skip to content
Prev 275594 / 398506 Next

Creating data frame with residuals of a data frame

try this:
+ x<- residuals(lm(data=df, formula= x ~ age))
+ }
+     newCol <- paste(i, 'res', sep = '')
+     df[[newCol]] <- NA  # initialize
+     df[[newCol]][as.integer(names(resid[[i]]))] <- resid[[i]]
+ }
age value1 value2  value1res   value2res
1   5     30      2 -16.945813 -0.37398374
2   6     70      4  22.906404  1.50406504
3  10     40      1  -7.684729 -1.98373984
4  14     50      4   1.724138  0.52845528
5  16     NA      4         NA  0.28455285
6  NA     NA      4         NA          NA
7  18     NA      4         NA  0.04065041


On Mon, Oct 24, 2011 at 10:23 AM, francesca casalino
<francy.casalino at gmail.com> wrote: