as.fmt.data.frame {fmtr}R Documentation

Convert a data frame to a user-defined format

Description

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".

Usage

## S3 method for class 'data.frame'
as.fmt(x)

Arguments

x

The data frame to convert.

Details

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.

Value

A format catalog based on the information contained in the input data frame.

Input Data Frame Specifications

The input data frame should contain the following columns:

Any additional columns will be ignored. Column names are case-insensitive.

Valid values for the "Type" column are as follows:

The "Label", "Order", and "Factor" columns are used only for a type "U", user-defined format created with the value function.

See Also

Other fmt: as.data.frame.fmt(), as.fmt(), condition(), is.format(), labels.fmt(), print.fmt(), value()

Examples

# 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 Factor
# 1 f1    U   x == "A" Label A    NA  FALSE
# 2 f1    U   x == "B" Label B    NA  FALSE
# 3 f1    U       TRUE   Other    NA  FALSE

# 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"

[Package fmtr version 1.6.5 Index]