Highlighting (with color) specific cell values in a dataframe

I am trying to locate errors within a data frame and highlight them. I can subset the values I want (see example code), but I don't know how to highlight the desired values upon export (i.e. the instances where "90210" or "Doctor" appear in df1).

I know you can't highlight a CSV, so exporting as an XLSX is probably the way to go.

Any help is soooo appreciated

df1 <- read.csv("My Data.csv")

Test <- subset(df1, df1$Zipcode == "90210" | df1$Occupation == "Doctor")

It is usually not a good idea to encode information in formatting. I suggest that you make a new column to mark the rows with errors.

df1$ErrorMarker <- df1$Zipcode == "90210" | df1$Occupation == "Doctor"

That column will be TRUE or FALSE depending on the tests. You can then easily filter for those rows and conveniently use functions to process them in place.

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.