I have a dataset in the following format -
Item Year
A 2018
B 2018
B 2019
A 2017
Z 2019
I select items only from 2018 using:
library(dplyr)
data2 <- data %>% filter(Year == "2018")
Now, when I get the counts of items using table(), there's a problem. The output looks like -
table(data2$Item)
A B Z
1 1 0
I don't understand why Z is included here. There are no Z items in data2. It messes up summary statistics.
Is there any way to prevent items from the original dataset being included? I tried filtering the original dataset without dplyr, but table() still returns the same output.