[R] How do I delete a row from a data frame when varA == "TRUE"

David Winsemius dwinsemius at comcast.net
Wed Jul 22 13:49:53 CEST 2009


On Jul 22, 2009, at 4:02 AM, Uwe Ligges wrote:

>
>
> Daniel Malter wrote:
>> XYZ=XYZ[XYZ$A==TRUE , ]
>
>
> install.packages("fortunes")
> library("fortunes")
> fortune("==TRUE")

I've also made the repeated unnecessary invocation of which() in this  
situation. But ... the OP asked for removal rather than inclusion of  
such rows. So wouldn't he want something likef:

>> XYZ=XYZ[!XYZ$A , ]

>
>
>
> Uwe Ligges
>
>
> > should do. Note that this specific command
>> overwrites your XYZ dataframe. If you want to keep XYZ, you will  
>> want to
>> name the newly created frame differently.
>> HTH,
>> Daniel
>> -------------------------
>> cuncta stricte discussurus
>> -------------------------
>> -----Ursprüngliche Nachricht-----
>> Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org 
>> ] Im
>> Auftrag von kxk
>> Gesendet: Wednesday, July 22, 2009 12:24 AM
>> An: r-help at r-project.org
>> Betreff: [R] How do I delete a row from a data frame when varA ==  
>> "TRUE"
>> I want to delete a row from a data frame XYZ where A == "TRUE".   
>> Let's
>> assume there are five variables in this data frame XYZ.  My  
>> deletion is
>> based on the TRUE vs. FALSE value under variable A.  How do I do  
>> this?
>> Thanks!
>> My current code: for (i in 1:length(XYZ$A)) if (XYZ$A == "FALSE")  
>> XYZ<-XYZ else XYZ<-
>> XYZ[-i,]
>> Error message is:
>> Error in if (XYZ$A == "FALSE") XYZ<-XYZ else XYZ<- XYZ[-i,  :    
>> missing value where TRUE/FALSE needed
>> Please help!!
>> --
>> View this message in context:
>> http://www.nabble.com/How-do-I-delete-a-row-from-a-data-frame-when-varA-%3D 
>> %
>> 3D-%22TRUE%22-tp24599876p24599876.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.
>> ______________________________________________
>> 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.
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list