Learn R Programming

hamlet (version 0.9.6)

mix.fun: Apply function to numerical columns of a mixed data.frame while ignoring non-numeric fields

Description

This function is intended for applying functions to numeric fields of a mixed type data.frame. Namely, the function ignores fields that are e.g. factors, and returns FUN function applied to only the numeric fields.

Usage

mix.fun(x, FUN = scale, ...)

Arguments

x

Data.frame x with mixed type fields

FUN

Function to apply, for example 'scale', 'cov', or 'cor'

Additional parameters passed on to FUN

Value

Return values of FUN when applied to numeric columns of 'x'

See Also

apply

Examples

Run this code
# NOT RUN {
data(vcapwide)

mix.fun(vcapwide[,c("Group", "PSAWeek4", "PSAWeek10", "PSAWeek14")], FUN=scale) 
# Column 'Group' is ignored
mix.fun(vcapwide[,c("Group", "PSAWeek4", "PSAWeek10", "PSAWeek14")], FUN=cov, use="na.or.complete") 
# ... is used to pass the 'use' parameter to the 'cov'-function
# }

Run the code above in your browser using DataLab