This function takes a data frame as input and converts it to a user-defined format based on the information contained in the data frame. The data frame should have 5 columns: "Name", "Type", "Expression", "Label" and "Order".
# S3 method for data.frame as.fmt(x)
x | The data frame to convert. |
---|
A format catalog based on the information contained in the input data frame.
The as.fmt.data.frame
function converts a data frame to a
user-defined format.
To understand the structure of the input data frame, create a user-defined
format and use the as.data.frame
method to convert the format
to a data frame.
Then observe the columns and organization of the data.
The input data frame should contain the following columns:
Name: The name of the format
Type: The type of format. See the type codes below.
Expression: The formatting expression. The expression will hold different types of values depending on the format type. Within the data frame, this expression is stored as a character string.
Label: The label for user-defined, "U" type formats.
Order: The order for user-defined, "U" type formats.
Any additional columns will be ignored. Column names are case-insensitive.
Valid values for the "Type" column are as follows:
U: User Defined List created with the value
function.
S: A formatting string of formatting codes. See FormattingStrings.
F: A vectorized function.
V: A named vector lookup.
The "Label" and "Order" columns are used only for a type "U", user-defined
format created with the value
function.
Other fmt:
as.data.frame.fmt()
,
as.fmt()
,
condition()
,
is.format()
,
labels.fmt()
,
print.fmt()
,
value()
# Create a user-defined format f1 <- value(condition(x == "A", "Label A"), condition(x == "B", "Label B"), condition(TRUE, "Other")) # Convert user-defined format to data frame to view the structure df <- as.data.frame(f1) print(df) # Name Type Expression Label Order # 1 f1 U x == "A" Label A NA # 2 f1 U x == "B" Label B NA # 3 f1 U TRUE Other NA # Convert data frame back to a user-defined format f2 <- as.fmt(df) # Use re-converted format fapply(c("A", "B", "C", "B"), f2) # [1] "Label A" "Label B" "Other" "Label B"