Last data update: 2014.03.03

R: converts variables of the data frame to factors
convertToFactorsR Documentation

converts variables of the data frame to factors

Description

the user specifies which variables he/she would like to consider as factors, the functions converts them to factors

Usage

convertToFactors(data, facs)

Arguments

data

data frame

facs

vector with names of variables that the user would like to convert to factors

Value

returns the same data frame as in the input but with the specified variables converted to factors

Author(s)

Alexandra Kuznetsova

Examples

library(SensMixed)

str(ham)

ham <- convertToFactors(ham, c("Gender"))

str(ham)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SensMixed)
Loading required package: lmerTest
Loading required package: Matrix
Loading required package: lme4

Attaching package: 'lmerTest'

The following object is masked from 'package:lme4':

    lmer

The following object is masked from 'package:stats':

    step


Attaching package: 'SensMixed'

The following object is masked from 'package:lmerTest':

    ham

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SensMixed/convertToFactors.Rd_%03d_medium.png", width=480, height=480)
> ### Name: convertToFactors
> ### Title: converts variables of the data frame to factors
> ### Aliases: convertToFactors
> 
> ### ** Examples
> 
> library(SensMixed)
> 
> str(ham)
'data.frame':	648 obs. of  6 variables:
 $ Consumer   : int  1 1 1 1 1 1 1 1 2 2 ...
 $ Product    : int  1 1 2 2 3 3 4 4 1 1 ...
 $ Liking     : int  5 5 4 4 4 6 6 6 5 5 ...
 $ Information: int  1 2 1 2 1 2 1 2 1 2 ...
 $ Gender     : int  1 1 1 1 1 1 1 1 2 2 ...
 $ Age        : int  46 46 46 46 46 46 46 46 48 48 ...
> 
> ham <- convertToFactors(ham, c("Gender"))
> 
> str(ham)
'data.frame':	648 obs. of  6 variables:
 $ Consumer   : int  1 1 1 1 1 1 1 1 2 2 ...
 $ Product    : int  1 1 2 2 3 3 4 4 1 1 ...
 $ Liking     : int  5 5 4 4 4 6 6 6 5 5 ...
 $ Information: int  1 2 1 2 1 2 1 2 1 2 ...
 $ Gender     : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 2 2 ...
 $ Age        : int  46 46 46 46 46 46 46 46 48 48 ...
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>