I am trying to create a series of gt tables with values shown to a 3rd sig fig. Because I want to show non numeric characters, the column I want to display is a factor. What's the best way to do this? I thought I could replace the values of a factor column with those from a numeric column, but I am not sure how to go about it. The code below is an example of a larger data set, where I would want to replace all numeric like values in Area1 with corresponding shorter values in Area2
Area1 <- as.factor(c(0,0, 0.50659782, "NS"))
Area2 <- c(NA, NA, 0.507, NA)
d <-data.frame(Area1, Area2) %>% gt()
Essentially, I want to Area1 column to look like
Area1
0
0
0.507
NS
Since your data has mixed types the numbers are already changed to characters/factors. You can use regex approach to keep data only till 3 decimal places.
library(gt)
Area1 <- as.factor(c(0,0, 0.50659782, "NS"))
Area2 <- c(NA, NA, 0.507, NA)
d <-data.frame(Area1, Area2)
d$Area1 <- ifelse(is.na(d$Area2), as.character(d$Area1), d$Area2)
d <- d[-2]
gt(d)