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.
transformC(type, x, data, response, cutpoints, groups, confirm = TRUE, ...)
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.
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"
The variable to be transformed, a variable that already exists, should be in dataset$var form unless dataset specified in optional data argument.
(Optional) Name of dataset that contains x variable.
(Optional) For type="dummy"
, response is the value or vector of values to be coded 1.
(Optional) For type="cut"
, a vector of values to serve as lower bounds of ranked categories for transformed x variable.
(Optional) For type="cut"
, the number of (approximately) same sized groups to create based on x values.
(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"
).
Transforming Variables with RCPA3 Package's transformC Function 22:40
Complete Playlist of RCPA3 Package Tutorial Videos, includes video for this function and many more.
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.
R Tutorials & Resources for Creating and Transforming Variables, Compiled by Barry C. Edwards
Sage Edge Resources for Political Analysis Series, for streaming videos, flashcards, and more student resources for textbooks by Pollock and Edwards, from Sage Publications.
Political Science Data Web Site: Find datasets for your own research and resources to help with the analysis.
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)
Run the code above in your browser using DataLab