'Filter Characters in an entire data frame with tidyverse

Hello I want to filter the following data frame

table

library(tidyverse)

datclear<-dat %>% filter(!grepl("vacio|--",dat$`question1-NATURALES`))

that way i get the following

tabla2

As you can see, I delete all the name data "vacio" then try to apply the same for all the data now including the data "--", to apply it to everything and remove "--" and try in a similar way to do it for a single column but it was removed exclusively in the column that I chose but not in the entire data frame and try the following code


datclear<-dat %>% filter(!grepl("vacio|--",dat))

Error: ! Problem with filter() input ..1.

i Input ..1 is !grepl("vacio|--", dat).

x Input ..1 must be of size 710 or 1, not size 102.

Run rlang::last_error() to see where the error occurred.

I would like to eliminate the two values ​​for the entire dataframe. I would like you with more experience to help me. I leave the data hosted on google drive below, thanks in advance

Data_U



Solution 1:[1]

Base R. You could start right when you read in the file, if you know that 'vacio' and '--' are really 'NA':

dat_U <- read.table('~/Downloads/dat_U.csv', header = TRUE, na.strings=c('vacio','--'), sep = ',')

then identify complete.cases():

dat_clean <-dat_U[which(complete.cases(dat_U) == TRUE), ]
str(dat_clean)
'data.frame':   335 obs. of  102 variables:
 $ Corr                  : int  11 12 14 15 17 18 19 21 26 28 ...
 $ sector                : chr  "Publico" "Publico" "Publico" "Publico" ...
 $ question1.NATURALES   : chr  "B" "C" "C" "C" ...
 $ question2.NATURALES   : chr  "C" "A" "B" "D" ...
 $ question3.NATURALES   : chr  "B" "D" "C" "A" ...
 $ question4.NATURALES   : chr  "A" "B" "A" "D" ...
 $ question5.NATURALES   : chr  "C" "A" "C" "B" ...
 $ question6.NATURALES   : chr  "D" "D" "C" "D" ...
 $ question7.NATURALES   : chr  "C" "A" "C" "C" ...
<------------------snip---------------------->

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris