[R] dplyr filter function returns all the levels

Elahe chalabi ch@|@b|@e|@he @end|ng |rom y@hoo@de
Fri Mar 27 12:17:57 CET 2020


Hello everyone,

I have the following dataframe 

        
    library(dplyr)
    dput(df)
    structure(list(Freq = c(19L, 19L, 18L, 15L, 14L, 13L, 13L, 12L, 
   11L, 11L, 11L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 9L), word1 = structure(c(3L, 
   11L, 5L, 6L, 11L, 3L, 7L, 10L, 8L, 11L, 13L, 1L, 1L, 4L, 5L, 
   9L, 12L, 14L, 2L), .Label = c("a", "art", "at", "by", "for", 
   "for ", "i", "is", "on", "said", "the", "there", "to", "when"
  ), class = "factor"), word2 = structure(c(13L, 12L, 13L, 13L, 
  6L, 13L, 5L, 8L, 11L, 4L, 2L, 3L, 10L, 13L, 13L, 13L, 1L, 9L, 
  7L), .Label = c("are", "be", "bit", "bottom", "dont", "end", 
  "hotel", "in", "it", "little", "one", "rest", "the"), class = "factor"), 
  word3 = structure(c(5L, 9L, 6L, 7L, 9L, 11L, 13L, 1L, 9L, 
  9L, 2L, 9L, 3L, 5L, 6L, 10L, 12L, 4L, 8L), .Label = c("a", 
  "able", "bit", "comes", "end", "first", "first ", "florence", 
  "of", "other", "same", "so", "want"), class = "factor"), 
  word4 = structure(c(5L, 9L, 10L, 8L, 9L, 10L, 11L, 7L, 9L, 
  9L, 11L, 1L, 5L, 5L, 6L, 2L, 4L, 11L, 3L), .Label = c("a", 
  "hand", "italy", "many", "of", "place", "statement", "states", 
  "the", "time", "to"), class = "factor")), class = "data.frame", row.names = c(NA, 
  -19L))


Is there a way to modify the following command so that the filter function doesn't return all the Levels?



   filter(df,(word1 == 'for' & word2 == 'the' & word3 == 'first')) $ word4
   [1] time  place
   Levels: a hand italy many of place statement states the time to



Thanks a lot! 
Elahe 



More information about the R-help mailing list