windows XP R 2.6.0 I am having problems deleting a row from a data frame. I create my dataframe by subsetting a larger dataframe: ShortLavin<-Lavin[Lavin[,"Site"]=="PP" | Lavin[,"Site"]=="CC" | Lavin[,"Site"]=="FH",] I then perform a glm using the data frame and plot the results. fit1poisson<-glm(NumUniqOpPt~Seq+Site,family=poisson(link = "log"),data=ShortLavin,offset=log(NumUniqPt)) plot(fit1poisson) On the plots I see a point labeled as 127 that is an extreme value. I want to re-run the glm excluding the extreme observation. I have tried several methods to exclude the observation (shown below), none have worked. Minus127<-ShortLavin[-127,] Minus127<-ShortLavin[-"127",] Minus127<-ShortLavin[-c(127),] Minus127<-ShortLavin[-c("127"),] None of these worked. Suggestions on how I can remove observation 127 would be appreciated Thank you, John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics 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) Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}}
On Tue, 4 Mar 2008, John Sorkin wrote:> windows XP > R 2.6.0 > > I am having problems deleting a row from a data frame. I create my dataframe by subsetting a larger dataframe: > > ShortLavin<-Lavin[Lavin[,"Site"]=="PP" | Lavin[,"Site"]=="CC" | Lavin[,"Site"]=="FH",] > > I then perform a glm using the data frame and plot the results. > > fit1poisson<-glm(NumUniqOpPt~Seq+Site,family=poisson(link = "log"),data=ShortLavin,offset=log(NumUniqPt)) > plot(fit1poisson) > > On the plots I see a point labeled as 127 that is an extreme value. I want to re-run the glm excluding the extreme observation. I have tried several methods to exclude the observation (shown below), none have worked. > > Minus127<-ShortLavin[-127,] > Minus127<-ShortLavin[-"127",] > Minus127<-ShortLavin[-c(127),] > Minus127<-ShortLavin[-c("127"),] > > None of these worked. Suggestions on how I can remove observation 127 would be appreciatedAssuming this is row name "127" derived from row 127 of the original dataset, Minus127 <- ShortLavin[-match("127", row.names(ShortLavin)), ]> > Thank you, > John > > John Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > 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)-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
try this: Minus127 <- ShortLavin[!row.names(ShortLavin) %in% "127", ] I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "John Sorkin" <jsorkin at grecc.umaryland.edu> To: <r-help at r-project.org> Sent: Tuesday, March 04, 2008 2:41 PM Subject: [R] subsetting a dataframe> windows XP > R 2.6.0 > > I am having problems deleting a row from a data frame. I create my > dataframe by subsetting a larger dataframe: > > ShortLavin<-Lavin[Lavin[,"Site"]=="PP" | Lavin[,"Site"]=="CC" | > Lavin[,"Site"]=="FH",] > > I then perform a glm using the data frame and plot the results. > > fit1poisson<-glm(NumUniqOpPt~Seq+Site,family=poisson(link = > "log"),data=ShortLavin,offset=log(NumUniqPt)) > plot(fit1poisson) > > On the plots I see a point labeled as 127 that is an extreme value. > I want to re-run the glm excluding the extreme observation. I have > tried several methods to exclude the observation (shown below), none > have worked. > > Minus127<-ShortLavin[-127,] > Minus127<-ShortLavin[-"127",] > Minus127<-ShortLavin[-c(127),] > Minus127<-ShortLavin[-c("127"),] > > None of these worked. Suggestions on how I can remove observation > 127 would be appreciated > > Thank you, > John > > John Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > 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) > > Confidentiality Statement: > This email message, including any attachments, is for\...{{dropped:14}}
On 3/4/2008 8:41 AM, John Sorkin wrote:> windows XP > R 2.6.0 > > I am having problems deleting a row from a data frame. I create my dataframe by subsetting a larger dataframe: > > ShortLavin<-Lavin[Lavin[,"Site"]=="PP" | Lavin[,"Site"]=="CC" | Lavin[,"Site"]=="FH",]I would do that in the following way: ShortLavin <- subset(Lavin, Site %in% c("PP","CC","FH"))> I then perform a glm using the data frame and plot the results. > > fit1poisson<-glm(NumUniqOpPt~Seq+Site,family=poisson(link = "log"),data=ShortLavin,offset=log(NumUniqPt)) > plot(fit1poisson)Of course, you could have done the subsetting within the call to glm: fit1poisson <- glm(NumUniqOpPt~Seq+Site,family=poisson(link = "log"), data=subset(Lavin, Site %in% c("PP","CC","FH")), offset=log(NumUniqPt))> On the plots I see a point labeled as 127 that is an extreme value. I want to re-run the glm excluding the extreme observation. I have tried several methods to exclude the observation (shown below), none have worked. > > Minus127<-ShortLavin[-127,] > Minus127<-ShortLavin[-"127",] > Minus127<-ShortLavin[-c(127),] > Minus127<-ShortLavin[-c("127"),] > > None of these worked. Suggestions on how I can remove observation 127 would be appreciatedMinus127 <- subset(ShortLavin, !rownames(ShortLavin) %in% 127)> Thank you, > John > > John Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > 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) > > Confidentiality Statement: > This email message, including any attachments, is for th...{{dropped:6}} > > ______________________________________________ > 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.-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894