My filter is not working

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

My filter is not working

christinelly
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
[hidden email]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
Reply | Threaded
Open this post in threaded view
|

Re: My filter is not working

franknarf
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 <[hidden email]> 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
[hidden email]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help


_______________________________________________
datatable-help mailing list
[hidden email]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help