transformC: Returns new variables by transforming existing dataset...

View source: R/transformC.r

transformCR Documentation

Returns new variables by transforming existing dataset variables (e.g. dummy variables, standardized variables, rank orders)

Description

Given a variable x, the transformC function generates and returns a tranformed version of x. For example, transformC can take a variable x and return standardized x, or the log of x.

Usage

transformC(type, x, data, response, cutpoints, groups, confirm = TRUE, ...)

Arguments

type

The type of transformation to be made to x. Options include:

  • "center"

  • "cut" use cutpoints or groups arguments to control cuts

  • "dummy" use response argument to identify values of x which should be coded 1 (all other non-missing responses will be coded 0)

  • "dummy.set"

  • "ln"

  • "log10"

  • "percent.rank"

  • "rank"

  • "whole"

  • "z"

x

The variable to be transformed, a variable that already exists, should be in dataset$var form unless dataset specified in optional data argument.

data

(Optional) Name of dataset that contains x variable.

response

(Optional) For type="dummy", response is the value or vector of values to be coded 1.

cutpoints

(Optional) For type="cut", a vector of values to serve as lower bounds of ranked categories for transformed x variable.

groups

(Optional) For type="cut", the number of (approximately) same sized groups to create based on x values.

confirm

(Optional) By default, transformC will ask you to confirm you want transformed variable returned (to prevent data loss). Set confirm=FALSE to bypass this check.

...

(Optional) Additional arguments pass to cut2 (for type="cut").

Value

A transformed version of x variable, a vector with the same length as x, unless type="dummy.set" in which case transformC returns a data.frame.

RCPA3 Package Tutorial Videos

Textbook References

  • Philip H. Pollock and Barry C. Edwards, An R Companion to Political Analysis, 3rd Edition (Thousand Oaks, CA: Sage Publications, Forthcoming 2022), Chapter 3.

  • Philip H. Pollock and Barry C. Edwards, The Essentials of Political Analysis, 6th Edition (Thousand Oaks, CA: Sage Publications, 2020), pp. 55-64. ISBN-13: 978-1506379616; ISBN-10: 150637961.

Online Resources

Examples

  library(RCPA3)
  
  # don't use confirm=FALSE until you've tested the function call
  transformC("percent.rank", nes$ft.dem, confirm=FALSE)
  transformC("rank", nes$ft.dem, confirm=FALSE)
  transformC("whole", runif(min=0,max=100,n=20), confirm=FALSE)

RCPA3 documentation built on May 29, 2024, 12:19 p.m.

Related to transformC in RCPA3...