[R] Problem dropping rows based on values in a column

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon Mar 26 06:00:51 CEST 2007


I think you want

delete <- c(14772,14744)
jdata <- subset(jdata, !(PID %in% delete))



Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred):   +61 7 3826 7251
Fax (if absolutely necessary):      +61 7 3826 7304
Mobile:                                   (I don't have one!)
Home Phone:                            +61 7 3286 7700
mailto:Bill.Venables at csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of John Sorkin
Sent: Monday, 26 March 2007 12:19 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Problem dropping rows based on values in a column

I am trying to drop rows of a dataframe based on values of the column
PID, but my strategy is not working. I hope someoen can tell me what I
am doing incorrectly.


# Values of PID column
> jdata[,"PID"]
 [1] 16608 16613 16355 16378 16371 16280 16211 16169 16025 11595 15883
15682 15617 15615 15212 14862 16539
[18] 12063 16755 16720 16400 16257 16209 16200 16144 11598 13594 15419
15589 15982 15825 15834 15491 15822
[35] 15803 15795 10202 15680 15587 15552 15588 15375 15492 15568 15196
10217 15396 15477 15446 15374 14092
[52] 14033 15141 14953 15473 10424 13445 14854 10481 14793 14744 14772

#Prepare to drop last two rows, rows that ahve 14744 and 14772 in the
PID column
> delete<-c(14772,14744)

#Try to delete last two rows, but as you will see, I am not able to drop
the last two rows.
> jdata[jdata$PID!=delete,"PID"]
 [1] 16608 16613 16355 16378 16371 16280 16211 16169 16025 11595 15883
15682 15617 15615 15212 14862 16539
[18] 12063 16755 16720 16400 16257 16209 16200 16144 11598 13594 15419
15589 15982 15825 15834 15491 15822
[35] 15803 15795 10202 15680 15587 15552 15588 15375 15492 15568 15196
10217 15396 15477 15446 15374 14092
[52] 14033 15141 14953 15473 10424 13445 14854 10481 14793 14744 14772
> 


Thanks,
John

John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence

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)
jsorkin at grecc.umaryland.edu

Confidentiality Statement:
This email message, including any attachments, is for the\ s...{{dropped}}



More information about the R-help mailing list