[datatable-help] My filter is not working
Frank Erickson
by.hook.or at gmail.com
Mon Oct 9 21:24:37 CEST 2017
This mailing list is about questions related to the data.table package. You
might want to try https://community.rstudio.com/ instead.
I'm not sure why your code doesn't work, but another approach would be
something like
DF %>% group_by(g) %>% summarise(count = sum(x != "yes"))
If this works, it's because TRUE/FALSE is treated as 1/0 when summed. You
might also want to look at the dplyr functions ?tally and ?count.
On Mon, Oct 9, 2017 at 3:20 PM, christinelly <01chrikelly at gmail.com> wrote:
> Hello,
>
> I am new to R, can someone please what is wrong with my code? I want to
> filter my result to only show people who have answered "no" but my result
> generates 0 rows. Does it have anything to do with the fact that my data is
> stored as factors and not characters?
>
> I also tried another code but gave me three rows, what am I doing wrong?
> Thanks in advance,
> Christine
>
> 'data.frame': 491775 obs. of 1 variable:
> $ hivtst6: Factor w/ 2 levels "Yes","No": 2 1 1 2 2 1 2 2 2 2 ...
>
> brfss2013 %>%
> filter(as.character(hivtst6) == "yes") %>%
> group_by(hivtst6) %>%
> summarise(count = n())
>
> brfss2013 %>%
> filter (hivtst6 != "yes") %>%
> group_by(hivtst6) %>%
> summarise(count = n())
>
> <http://r.789695.n4.nabble.com/file/t385588/Screen_Shot_
> 2017-10-09_at_21.png>
>
>
>
> --
> Sent from: http://r.789695.n4.nabble.com/datatable-help-f2315188.html
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/
> listinfo/datatable-help
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20171009/41cecfb8/attachment.html>
More information about the datatable-help
mailing list