The fapply2 function applies formatting to two different vectors, and combines them into a single vector. This function is useful in cases where your data is in two different variables, and you would like them displayed as a single column for reporting purposes. For example, if you wish to create one column to display mean and standard deviation.

fapply2(
x1,
x2,
format1 = NULL,
format2 = NULL,
sep = " ",
width = NULL,
justify = NULL
)

## Arguments

x1 A vector, factor, or list to apply the format1 to. A second vector, factor, or list to which format2 will be applied. A format to be applied to the first input. A format to be applied to the second input. A separator to use between the two formatted values. Default is a single blank space (" "). The desired character width of the formatted vector. Default value is NULL, meaning the vector will be variable width. Whether to justify the return vector. Valid values are 'left', 'right', 'center', 'centre', or 'none'.

## Value

A vector of formatted values.

## Details

The fapply2 function works nearly the same as fapply. The difference is it has parameters for two vectors and formats instead of one. The output of the function is a single vector. The function essentially calls fapply on each vector and pastes them together afterwards.

There is an additional sep parameter so you can define a separator between the two formatted values. The width and justify parameters will apply to the single vector result. The function will also pick up format attributes on the supplied vectors.

The fapply2 function accepts any of the format types that fapply accepts. See fapply for additional information on the types of formats that can be applied.

Parameters may also be passed as attributes on the vector. See the fattr function for additional information on setting formatting attributes.

## See also

fapply to format a single input, fcat to create a format catalog, value to define a format, fattr to easily set the formatting attributes of a vector, and flist to define a formatting list. Also see fdata to apply formats to an entire data frame, and FormattingStrings for how to define a formatting string.

## Examples

# Create sample data
dt <- c(2.1, 5, 6, 9, 2, 7, 3)

# Calculate mean and standard deviation
v1 <- mean(dt)
v2 <- sd(dt)

# Apply formats and combine
fapply2(v1, v2, "%.1f", "(%.2f)")
# [1] "4.9 (2.66)"