# NOT RUN {
# Take subset of data
df1 <- mtcars[1:10, c("mpg", "cyl") ]
# Print current state
print(df1)
# Assign formats
attr(df1$mpg, "format") <- value(condition(x >= 20, "High"),
condition(x < 20, "Low"))
attr(df1$cyl, "format") <- function(x) format(x, nsmall = 1)
# Display formatted data
format(df1)
# Extract format list
lst <- formats(df1)
# Alter format list and reassign
lst$mpg <- value(condition(x >= 22, "High"),
condition(x < 22, "Low"))
lst$cyl <- function(x) format(x, nsmall = 2)
formats(df1) <- lst
# Display formatted data
format(df1)
# }
Run the code above in your browser using DataLab