filter() function

Hi everybody , I,m trying to select a set of data but when I executed the filter() don't show any error but when I review the don't show nothing

library(dplyr)
library(stringr)
library(gapminder)
library(tidyverse)

paa_codazzi2 <- paa_codazzi %>%
rename(Entidad = ...1,Codigo = ...2, Descripcion=...3,Fecinicpro = ...4,fecpofer = ...5,plazo = ...6,unidad_plazo = ...7,modalidad = ...8,fuente = ...9,valor =...10,vlrvigactu = ...11)
list_codigos<-c("42203605","4323","81111","81112","81122","81123","81161501")

paa_codazzi3<-mutate(paa_codazzi2,indicador=" ")
filter(paa_codazzi3,paa_codazzi3$Codigo %in% list_codigos)

It looks like it should work. Can you provide a reproducible example of paa_codazzi?

If you want to keep the result of filter() you should use <- to assign the result to a name that you can call and review later.

Filter in R is one of temporary o/p functions , that's why you you've to assign a variable for filter function ,

df1 <- filter (....,......)

then using df1 in next steps will keep filter results every time.

Thank you William , using the reprex I realized the data type of codigo column is numeric not a string , now I´m trying to convert this column as character. If you can give me any guidance about how make this I appreciate.

This should work.

paa_codazzi3 <- paa_codazzi2 %>% 
  mutate(indicator = " ",
         Codigo = as.character(Codigo)) %>% 
  filter(Codigo %in% list_codigos)

Thank you William this works very well, I save a lot time. Thank you so much

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.