[R] can not extract rows which match a string

Richard O'Keefe r@oknz @end|ng |rom gm@||@com
Fri Oct 4 07:28:14 CEST 2019


I think the problem may lie in your understanding of what "==" does with NA
and/or what "[]" does with NA.
> x <- c(NA, "Yes")
> x == "Yes"
[1]   NA TRUE
Since you say you DON'T want the rows with "Yes", you just want
x[is.na(x)]
or in your case
t11 <- t1[is.na(t1$sex_chromosome_aneuploidy_f22019_0_0),]
or if there could be other values than "Yes" that you want to keep,
is.definitely <- function (x, y) {
   !is.na(x) & !is.na(y) & x == y
}
t11 <- t1[!is.definitely(t1$sex_chromosome_aneuploidy_f22019_0_0, "Yes"),]

On Fri, 4 Oct 2019 at 07:59, Ana Marija <sokovic.anamarija using gmail.com> wrote:
>
> Hello,
>
> I have a dataframe (t1) with many columns, but the one I care about it this:
> > unique(t1$sex_chromosome_aneuploidy_f22019_0_0)
> [1] NA    "Yes"
>
> it has these two values.
>
> I would like to remove from my dataframe t1 all rows which have "Yes"
> in t1$sex_chromosome_aneuploidy_f22019_0_0
>
> I tried selecting those rows with "Yes" via:
>
> t11=t1[t1$sex_chromosome_aneuploidy_f22019_0_0=="Yes",]
>
> but I got t11 which has the exact same number of rows as t1.
>
> If I do:
> > table(t1$sex_chromosome_aneuploidy_f22019_0_0)
>
> Yes
> 620
>
> So there is for sure 620 rows which have "Yes". How to remove those
> from my t1 data frame?
>
> Thanks
> Ana
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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