[R] Eliminate cases in a subset of a dataframe

John Kane jrkrideau at yahoo.ca
Mon Sep 14 19:06:37 CEST 2009


At a quick glance, your code seems to be deleting columns not rows

try y[-c(11,22,33), ]  

--- On Mon, 9/14/09, Hollix <Holger.steinmetz at web.de> wrote:

> From: Hollix <Holger.steinmetz at web.de>
> Subject: [R]  Eliminate cases in a subset of a dataframe
> To: r-help at r-project.org
> Received: Monday, September 14, 2009, 10:57 AM
> 
> Hi folks,
> 
> I created a subset of a dataframe (i.e., selected only
> men):
> 
> subdata <- subset(data,data$gender==1)
> 
> After a residual diagnostic of a regression analysis, I
> detected three
> outliers:
> 
> linmod <- lm(y ~ x, data=subdata)
> plot(linmod)
> 
> Say, the cases 11,22, and 33 were outliers.
> 
> Here comes the problem: When I want to exclude these three
> cases in a
> further regression analysis, 
> - for instance with linmod2 <- lm(y[-c(11,22,33)] ~
> x[-c(11,22,33)],
> data=subdata) - it does not work.
> 
> I guess this has something to do with this strange
> "row.names"-vector which
> has been added to the dataframe when creating the subset. I
> find it very
> strange why R gives the case numbers in the diagnostics but
> then doesn't
> allow me to use these numbers for further exclusion. 
> 
> Can anybody tell me:
> 1. what this row.names vector is
> 2. How I can refer to cases after creating a subset (e.g.,
> in order to
> exclude them).
> 
> Many thanks in advance,
> Best,
> Holger
> -- 
> View this message in context: http://www.nabble.com/Eliminate-cases-in-a-subset-of-a-dataframe-tp25437374p25437374.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.
> 


      __________________________________________________________________
[[elided Yahoo spam]]




More information about the R-help mailing list