Beatriz González Domínguez
2013-Apr-07 18:31 UTC
[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]]
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.