-2

Solved

I cached some excel files into csv's, problem is in the excel sheets rather than giving blank values where none exists, there is inputted "x" or "xx" up to "xxxxx" and I need to convert all of those into NA's. What should I do? Some of the more complicated functions that I find in solutions online in R don't make sense to me (like apply + function + grepl) but I can understand things like grepl individually however cannot seem to find something that works.

I have tried

df <- replace(df, df == grepl(df, "x"), NA) %>%
write_csv("df.csv") 

However I get an

error: my df (pattern in grepl) has length >1

and only the first element will be used (I'm assuming the first column).

I've also done things individually by column, but I'm looking for something that scales. Thanks!

1 Answers1

0
df[sapply(df, grepl, pattern = 'x')] <- NA
IceCreamToucan
  • 28,083
  • 2
  • 22
  • 38