Ramakrishna S
Ramakrishna S

Reputation: 437

How to Check which type of data type can a function takes in R

I know that collapse::fmean function can be applied to data.frames as well as a single vector. But is there any way to check the kind of data a function accept in R?

collapse::fmean(mtcars)
#>        mpg        cyl       disp         hp       drat         wt       qsec 
#>  20.090625   6.187500 230.721875 146.687500   3.596562   3.217250  17.848750 
#>         vs         am       gear       carb 
#>   0.437500   0.406250   3.687500   2.812500
collapse::fmean(mtcars$mpg)
#> [1] 20.09062

Created on 2022-10-15 by the reprex package (v2.0.1)

Upvotes: 0

Views: 33

Answers (1)

Redsnic
Redsnic

Reputation: 42

Often R functions come with their own documentation. You can read it by using the command ?<function>, so in your case ?collapse::fmean (or equivalently help(collapse::fmean)).

For example this is how the help page for that function looks in RStudio:

enter image description here

As you can see in the last line, in this case it is clearly specified what kind of data is accepted for variable x.

Upvotes: 1

Related Questions