var_type: Determine variable type

Description Usage Arguments Value Examples

View source: R/var_type.R

Description

This function returns the type of a variable as character. It is similar to pillar::type_sum(), however, the return value is not truncated, and var_type() works on data frames and within pipe-chains.

Usage

1
var_type(x, ..., abbr = FALSE)

Arguments

x

A vector or data frame.

...

Optional, unquoted names of variables that should be selected for further processing. Required, if x is a data frame (and no vector) and only selected variables from x should be processed. You may also use functions like : or tidyselect's select-helpers. See 'Examples' or package-vignette.

abbr

Logical, if TRUE, returns a shortened, abbreviated value for the variable type (as returned by pillar::type_sum()). If FALSE (default), a longer "description" is returned.

Value

The variable type of x, as character.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data(efc)

var_type(1)
var_type(1L)
var_type("a")

var_type(efc$e42dep)
var_type(to_factor(efc$e42dep))

library(dplyr)
var_type(efc, contains("cop"))

Example output

[1] "numeric"
[1] "integer"
[1] "character"
[1] "numeric"
[1] "categorical"

Attaching package:dplyrThe following objects are masked frompackage:stats:

    filter, lag

The following objects are masked frompackage:base:

    intersect, setdiff, setequal, union

  c82cop1   c83cop2   c84cop3   c85cop4   c86cop5   c87cop6   c88cop7   c89cop8 
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" 
  c90cop9 
"numeric" 

sjmisc documentation built on Dec. 11, 2021, 9:34 a.m.