[R] Deleting rows based on identity variable

Rowe, Brian Lee Yung (Portfolio Analytics) B_Rowe at ml.com
Thu Apr 2 22:37:53 CEST 2009


Is this what you want:
> d1[which(id != 4),]
      id x    y
 [1,]  1 1 0.00
 [2,]  1 2 0.10
 [3,]  1 3 0.50
 [4,]  1 4 0.40
 [5,]  1 5 0.20
 [6,]  2 1 0.00
 [7,]  2 2 0.10
 [8,]  2 3 0.50
 [9,]  2 4 0.40
[10,]  2 5 0.12
[11,]  3 1 0.00
[12,]  3 2 0.10
[13,]  3 3 0.50
[14,]  3 4 0.55
[15,]  3 5 0.20
[16,]  5 1 0.00
[17,]  5 2 0.10
[18,]  5 3 0.60
[19,]  5 4 0.40
[20,]  5 5 0.10

-----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 4:30 PM
To: R-help at r-project.org
Subject: [R] Deleting rows based on identity variable


I have created this data frame to help illustrate my problem.

id<-c(rep(1,5),rep(2,5),rep(3,5),rep(4,5),rep(5,5))
x<-rep((seq(1:5)),5)
y<-c(0, 0.1, 0.5, 0.4, 0.2, 0, 0.1, 0.5, 0.4, 0.12, 0, 0.1, 0.5, 0.55, 0.2, 0, 0.1, 0.5, 0.3, 0.2, 0, 0.1, 0.6, 0.4, 0.1)
d1<-cbind(id,x,y)

I would like to delete all rows where id=4, however, when I tried the command

 d2=d1[-c(id==4),]

and looked at d2 no data was removed.

Thanks in advance, I appreciate any help.




      
	[[alternative HTML version deleted]]


--------------------------------------------------------------------------
This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. References to "Merrill Lynch" are references to any company in the Merrill Lynch & Co., Inc. group of companies, which are wholly-owned by Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this E-communication may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.
--------------------------------------------------------------------------




More information about the R-help mailing list