An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090402/6f655536/attachment-0001.pl>
Deleting rows based on identity variable
3 messages · gina patel, Nordlund, Dan (DSHS/RDA), Baptiste Auguie
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of gina patel Sent: Thursday, April 02, 2009 2:17 PM To: Brian Lee Yung (Portfolio Analytics)Rowe; hadley wickham Cc: R-help at r-project.org Subject: Re: [R] Deleting rows based on identity variable I have another question, if I now want to remove multiple id's e.g. id=1 or 4 is there a simple OR command I can use? I tried? d2<-(d1[id != 1 | 4, ]) however this does not delete anything PS? d2<-(d1[id != 4, ]) worked to remove id=4 Thanks Gina --- On Thu, 4/2/09, hadley wickham <h.wickham at gmail.com> wrote: From: hadley wickham <h.wickham at gmail.com> Subject: Re: [R] Deleting rows based on identity variable To: "Rowe, Brian Lee Yung (Portfolio Analytics)" <B_Rowe at ml.com> Cc: "gina patel" <ginapatel1981 at yahoo.com>, R-help at r-project.org Date: Thursday, April 2, 2009, 4:48 PM On Thu, Apr 2, 2009 at 3:37 PM, Rowe, Brian Lee Yung (Portfolio Analytics) <B_Rowe at ml.com> wrote:
Is this what you want:
d1[which(id != 4),]
Or just d1[id != 4, ] Hadley -- http://had.co.nz/
The problem is rules of precedence for evaluation. Try d2<-d1[!(id %in% c(1,4)), ] Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
just for curiosity, `%ni%` <- Negate(`%in%`) > 1 %ni% c(2,1) [1] FALSE d1[id %ni% c(1,4), ] baptiste
On 2 Apr 2009, at 22:17, gina patel wrote:
I have another question, if I now want to remove multiple id's e.g. id=1 or 4 is there a simple OR command I can use? I tried d2<-(d1[id != 1 | 4, ]) however this does not delete anything PS d2<-(d1[id != 4, ]) worked to remove id=4 Thanks Gina --- On Thu, 4/2/09, hadley wickham <h.wickham at gmail.com> wrote: From: hadley wickham <h.wickham at gmail.com> Subject: Re: [R] Deleting rows based on identity variable To: "Rowe, Brian Lee Yung (Portfolio Analytics)" <B_Rowe at ml.com> Cc: "gina patel" <ginapatel1981 at yahoo.com>, R-help at r-project.org Date: Thursday, April 2, 2009, 4:48 PM On Thu, Apr 2, 2009 at 3:37 PM, Rowe, Brian Lee Yung (Portfolio Analytics) <B_Rowe at ml.com> wrote:
Is this what you want:
d1[which(id != 4),]
Or just d1[id != 4, ] Hadley -- http://had.co.nz/ [[alternative HTML version deleted]] <ATT00001.txt>
_____________________________ Baptiste Augui? School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag