How do comparations with factors?

Asked by At

I have a data frame and one of the columns is a factor:

   summary(dados)
 Churn     
 False.:4293  
 True. : 707

   dados$Churn

[993]  False.  False.  False.  False.  False.  False.  False.  False.
[ reached getOption("max.print") -- omitted 4000 entries ]
   Levels:  False.  True.

I want to filter only the falses. But when I do: dados['Churn'] == 'False.' The code returns me only FALSE.

Should I need to do something different to make a comparison with a dataframe?

1 Answers

0
Artem On

Your problem is not reproducible. Addressing the column by its name - its perfectly legit. Please see the code below.

#data simulation
set.seed(123)
dados <- data.frame(Churn = sample(c("False.", "True."), 5000, replace = TRUE))
summary(dados)  
# Churn     
# False.:2521  
# True. :2479  

head(dados$Churn)
# [1] False. True.  False. True.  True.  False.
# Levels: False. True.

# subsetting
head(dados['Churn'] == 'False.')
# Churn
# [1,]  TRUE
# [2,] FALSE
# [3,]  TRUE
# [4,] FALSE
# [5,] FALSE
# [6,]  TRUE