[R] can not extract rows which match a string
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Thu Oct 3 22:27:43 CEST 2019
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"
Hope this helps,
Rui Barradas
Às 21:21 de 03/10/19, Rui Barradas escreveu:
> 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_chromosome_aneuploidy_f22019_0_0
>> in other words to REMOVE rows with "Yes" and to keep rows with NA. How
>> to do that?
>>
>> On Thu, Oct 3, 2019 at 2:26 PM Rui Barradas <ruipbarradas using sapo.pt> wrote:
>>>
>>> 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 Barradas
>>>
>>> Às 19:58 de 03/10/19, Ana Marija escreveu:
>>>> 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.
>>>>
>
> ______________________________________________
> 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