Re: [R] selecting rows for inclusion in lm

From: David Barron <mothsailor_at_googlemail.com>
Date: Thu 18 Jan 2007 - 08:19:58 GMT

Why not use the subset option? Something like:

lm(diff ~ Age + Race, data=data, subset=data$Meno=="PRE")

should do the trick, and be much easier to read!

On 18/01/07, John Sorkin <jsorkin@grecc.umaryland.edu> wrote:
> I am having trouble selecting rows of a dataframe that will be included
> in a regression. I am trying to select those rows for which the variable
> Meno equals PRE. I have used the code below:
>
> difffitPre<-lm(data[,"diff"]~data[,"Age"]+data[,"Race"],data=data[data[,"Meno"]=="PRE",])
> summary(difffitPre)
>
> The output from the summary indicates that more than 76 rows are
> included in the regression:
>
> Residual standard error: 2.828 on 76 degrees of freedom
>
> where in fact only 22 rows should be included as can be seen from the
> following:
>
> print(data[length(data[,"Meno"]=="PRE","Meno"]))
> [1] 22
>
> I would appreciate any help in modifying the data= parameter of the lm
> so that I include only those subjects for which Meno=PRE.
>
> R 2.3.1
> Windows XP
>
> Thanks,
> John
>
> John Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> Baltimore VA Medical Center GRECC,
> University of Maryland School of Medicine Claude D. Pepper OAIC,
> University of Maryland Clinical Nutrition Research Unit, and
> Baltimore VA Center Stroke of Excellence
>
> University of Maryland School of Medicine
> Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
>
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
> jsorkin@grecc.umaryland.edu
>
> Confidentiality Statement:

> This email message, including any attachments, is for the so...{{dropped}}
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

-- 
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Thu Jan 18 19:27:15 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 18 Jan 2007 - 09:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.