mix.fun: Apply function to numerical columns of a mixed data.frame...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/mixtools.R

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

1
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'

Author(s)

Teemu Daniel Laajala <teelaa@utu.fi>

See Also

apply

Examples

1
2
3
4
5
6
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

Example output

          PSAWeek4   PSAWeek10    PSAWeek14
ID003  0.813057342  1.03297829 -0.368672890
ID007 -1.091185840 -1.07818709 -0.586788716
ID008  0.586053677  1.38304790  1.279313346
ID009  1.051822855 -0.21529622  0.040294282
ID010 -1.374646375 -0.71736973 -0.648891138
ID016 -0.550140834  0.07335767  0.966150520
ID018 -0.590131117 -0.16002207 -0.375110336
ID025  1.337635760 -0.22143779 -1.392605515
ID027 -0.239628049 -0.76496691 -0.005146515
ID031  0.156746227 -1.15649213 -0.994619868
ID032  0.293183663 -0.93386014 -0.219854280
ID037  0.369635675 -0.12777882  2.114287990
ID040  1.766943210  1.38918947  0.157683008
ID045 -0.124361939 -0.04640299  0.616635057
ID047 -1.387584408 -1.22865560 -0.883668589
ID054 -0.719511445  3.09347570  3.479783939
ID056  0.449616241  2.08472250  0.712818077
ID058 -0.104366797 -0.74193602 -0.456146424
ID075 -1.508731442 -1.15802752  0.312939064
ID078  0.317883544 -0.70201580 -1.026428426
ID083 -1.173518775 -0.58225515           NA
ID084 -1.564012127 -0.83559499 -0.369808910
ID087 -0.538378986  1.93271859  1.721982443
ID093  0.002666019 -0.71890512 -0.949936418
ID097  1.163560411  0.25760483 -0.013856001
ID100 -1.468741159 -0.70815737 -0.733713959
ID101  1.430554359  0.26374640  0.785523353
ID103 -0.761854097 -0.95382025 -0.322096073
ID104  2.248002791 -0.12470803 -1.002572008
ID113  1.277650336 -0.51009168 -1.005980067
ID116  1.362335641  1.18498220 -0.897300828
ID121  1.212960172  0.75814294  0.652230348
ID125 -0.454869866  0.51401546 -0.660251337
ID138 -0.183171179  0.27910033  1.324754143
ID141 -1.309956211 -0.35348159 -0.729927226
ID144  0.596639340 -0.60989222 -0.425095213
ID152 -0.044381373  0.01808352  1.256214274
ID157 -0.966510252 -0.98913429  0.623829850
ID158 -0.795963456 -1.13039045 -1.074519936
ID160  1.203550694  0.98538111  1.081267206
ID162  1.124746312  0.23150314 -0.557252198
ID174 -0.149061820  1.58725517  0.014923171
ID182 -0.667759314 -0.68205569 -0.677670309
ID192 -0.313727691  0.63531150 -0.448194285
ID198 -0.683049716 -0.25368104 -0.314522607
attr(,"scaled:center")
 PSAWeek4 PSAWeek10 PSAWeek14 
 17.86733  14.57222  37.37591 
attr(,"scaled:scale")
 PSAWeek4 PSAWeek10 PSAWeek14 
 8.502065  6.512990 26.407988 
           PSAWeek4 PSAWeek10  PSAWeek14
PSAWeek4  71.598499  19.45375  -2.849299
PSAWeek10 19.453753  43.06349 104.137805
PSAWeek14 -2.849299 104.13780 697.381806

hamlet documentation built on May 1, 2019, 8:40 p.m.