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

Daniel Malter daniel at umd.edu
Wed Jul 22 07:13:42 CEST 2009


XYZ=XYZ[XYZ$A==TRUE , ] 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.




More information about the R-help mailing list