[R] Format of Output of Residuals

Michael Just mgjust at gmail.com
Mon Oct 4 22:50:44 CEST 2010


Thank you this was worked great. Thank you for the additional
information as well. Knowledge is power.

Cheers,
Michael

On Fri, Oct 1, 2010 at 5:34 AM, Dennis Murphy <djmuser at gmail.com> wrote:
>
> Hi:
>
> CW.lm <- lm(weight ~ Diet, ChickWeight)
> resid.CW.lm <- resid(CW.lm)
> as.data.frame(resid(CW.lm))[1:10, ]      # (nope)
>  [1] -60.645455 -51.645455 -43.645455 -38.645455 -26.645455  -9.645455
>  [7]   3.354545  22.354545  46.354545  68.354545
> # convert residuals to one column matrix, then convert to data frame:
> as.data.frame(matrix(resid(CW.lm), ncol = 1))
>               V1
> 1    -60.6454545
> 2    -51.6454545
> 3    -43.6454545
> 4    -38.6454545
> 5    -26.6454545
> ...
>
> HTH,
> Dennis
>
> On Thu, Sep 30, 2010 at 9:09 PM, Michael Just <mgjust at gmail.com> wrote:
>>
>> An excerpt from dataset ChickWeight:
>>     weight Time Chick Diet
>> 1       42    0     1    1
>> 2       51    2     1    1
>> 3       59    4     1    1
>>
>> I am interested in the residuals of the dataset.  Specifically in
>> saving them to another format. I have been creating text files with
>> sink.
>>
>> CW.lm <- lm(weight ~ Diet, ChickWeight)
>> resid.CW.lm <- resid(CW.lm)
>>
>> But when I call:
>> resid.CW.lm
>>
>> The data appears like this (excerpt) :
>>
>>            1            2            3            4            5            6
>>  -60.6454545  -51.6454545  -43.6454545  -38.6454545  -26.6454545   -9.6454545
>>
>> How can I get the data to be formatted like below in an output / sink
>> friendly way?
>>
>> 1 -60.6454545
>> 2 -51.6454545
>> 3 -43.6454545
>> 4 -38.6454545
>> 5 -26.6454545
>> 6 -9.6454545
>>
>> Thank you kindly,
>> Cheers,
>> Mike
>>
>> ______________________________________________
>> R-help at 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.
>



More information about the R-help mailing list