[R] subset data frame problem

Kai Yang y@ngk@|9999 @end|ng |rom y@hoo@com
Mon Dec 13 17:30:24 CET 2021


 Thans Richard, it works well. --- Kai
    On Monday, December 13, 2021, 04:00:33 AM PST, Richard O'Keefe <raoknz using gmail.com> wrote:  
 
 You want to DELETE rows satisfying the condition P & Q.The subset() function requires an expression saying whatyou want to RETAIN, so you need subset(PD, !(P & Q)).
test <- subset(PD, !(Class == "1st" & Survived == "No"))
By de Morgan's laws, !(P & Q) is the same as (!P) | (!Q)so you could also write
test <- subset(PD, Class != "1st" | Survived != "No")
I'd actually be tempted to do this in two steps:
unwanted <- PD$Class == "1st" & PD$Survived == "No"test <- PD[!unwanted,]



On Mon, 13 Dec 2021 at 17:30, Kai Yang via R-help <r-help using r-project.org> wrote:

Hi R team,I want to delete records from a data frame if Class = '1st' and Survived = 'No'. I wrote the code below, test <- subset(PD, Class != '1st' && Survived != 'No')
but the code return a wrong result. Can someone help me for this? 
Thanks,Kai
        [[alternative HTML version deleted]]

______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

  
	[[alternative HTML version deleted]]



More information about the R-help mailing list