Re: [R] can not extract rows which match a string

2019-10-04 Thread William Michels via R-help
Apologies Ana, Of course Rui and Herve (and Richard) are correct here in stating that NA values get 'carried through' when selecting using the "==" operator. To give an illustration of what (I believe) Herve means by "NAs propagating", here's a small 11 x 8 dataframe ("zakaria") posted to R-Help l

Re: [R] can not extract rows which match a string

2019-10-03 Thread Richard O'Keefe
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

Re: [R] can not extract rows which match a string

2019-10-03 Thread Pages, Herve
Hi, On 10/3/19 11:58, Ana Marija 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

Re: [R] can not extract rows which match a string

2019-10-03 Thread Rui Barradas
Hello again, Sometimes it's better to create indices for each condition and then assemble them with logical operations as needed. i <- t1$sex_chromosome_aneuploidy_f22019_0_0 == "Yes" j <- is.na(t1$sex_chromosome_aneuploidy_f22019_0_0) t1[!i & j, ] j means is.na(.) !i means (.) != "Yes"

Re: [R] can not extract rows which match a string

2019-10-03 Thread Rui Barradas
Hello, Then it's easier, is.na alone will do it. j <- is.na(t1$sex_chromosome_aneuploidy_f22019_0_0) t1[j, ] Hope this helps, Rui Barradas Às 20:29 de 03/10/19, Ana Marija escreveu: Hi Rui, sorry for confusion, I would only need to extract from my t1 dataframe rows which have NA in sex_ch

Re: [R] can not extract rows which match a string

2019-10-03 Thread William Michels via R-help
Hello, I expected the code you posted to work just as you presumed it would, but without a reproducible example--I can only speculate as to why it didn't. In the t1 dataframe, if indeed you only want to remove rows of the t1$sex_chromosome_aneuploidy_f22019_0_0 column which are undefined, you cou

Re: [R] can not extract rows which match a string

2019-10-03 Thread Rui Barradas
Hello, You have to use is.na to get the NA values. t1 <- data.frame(sex_chromosome_aneuploidy_f22019_0_0 = c(NA, "Yes"), other = 1:2) i <- t1$sex_chromosome_aneuploidy_f22019_0_0 == "Yes" & !is.na(t1$sex_chromosome_aneuploidy_f22019_0_0) i t1[i, ] Hope this helps, Rui Bar