0

I have got that issue I can't my head around:

library(dplyr)

d<-data.frame(c1=c("a","a","b","b"),c2=c(1,1,3,4))

dFiltered <-  d %>%
  filter(c1 == "a") %>%
  select(c1)

> dFiltered
  c1
1  a
2  a

so then I want to create a data.frame to get the frequency of c1 based on the filtered data

> data.frame(table(dFiltered))
  dFiltered Freq
1         a    2
2         b    0

I don't understand why the value b appears as well even though it shows 0, I don't expect to find it here because if I run the same but selecting a value from c2

> dFiltered <-  d %>%
   filter(c2 == "1") %>%
   select(c2)
> data.frame(table(dFiltered))

then I get what I expect

  dFiltered Freq
1         1    2

I am sure there is a rational explanation to this

0 Answers0