[R] Remove a row containing a specific value for a column

arun smartpink111 at yahoo.com
Sun Apr 7 20:36:19 CEST 2013


Hi,
DATA[DATA$A!="Blue1",]
#     A B C D
#1 Red1 1 1 1
#3 Red2 1 1 1
#4 Red3 1 1 1
#or
DATA[!grepl("Blue1",DATA$A),]
#     A B C D
#1 Red1 1 1 1
#3 Red2 1 1 1
#4 Red3 1 1 1
A.K.




----- Original Message -----
From: Beatriz González Domínguez <aguitatierra at hotmail.com>
To: r-help at r-project.org; R Help <r-help-bounces at r-project.org>
Cc: 
Sent: Sunday, April 7, 2013 2:31 PM
Subject: [R] Remove a row containing a specific value for a column

Dear all,

Could anyone help me with the following?

DATA <- data.frame(rbind(c("Red1", 1, 1, 1), c("Blue1", 1, 1, 1), c("Red2", 1, 1, 1), c("Red3", 1, 1, 1)))
colnames(DATA) <- c("A", "B","C", "D")

#Option 1
DATA <- DATA[-2, ] #Same result I would like to achieve with Option 2

#Option 2 - I would like to do it in this way. Do you know how it could be done?
#DATA <- THE CODE WOULD SAY (Remove the row which contains the value "Blue1" in column "A")

Many thanks!

Bea
    [[alternative HTML version deleted]]

______________________________________________
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