sortC {RCPA3} | R Documentation |
Sorts dataset observations by user-defined criteria to return case-level information
Description
Returns case-level information in order specified by user. You can sort by additional criteria to break ties. Useful for learning about units of analysis and selecting cases for qualitative research designs.
Usage
sortC(id, by, data, thenby, descending = TRUE, limit, confirm = TRUE,
printC = FALSE)
Arguments
id |
A variable in the dataset (data) that identfies individual cases, typically the name of states, countries, etc. |
by |
Variable the cases should be sorted by. |
data |
(Optional) Dataset to be sorted. |
thenby |
(Optional) Criteria for sorting cases after sorting with the "by" variable. Useful if many cases tied on first criteria. |
descending |
(Optional) Should the cases be sorted in descending order? By default, set to TRUE. When sorting ordered factors, check that the levels higher numerically correspond to the sort order you have in mind. |
limit |
(Optional) The number of rows to report. If there are many observations to be sorted, you may want to limit output to 5, 10, etc. rows. |
confirm |
(Optional) If function is going to return long table of results (more than 20 rows), you'll be asked for confirmation (use |
printC |
(Optional) Do you want to print table of sorted observations to to .html file in working directory? (default: FALSE) |
Value
A data frame of sorted observations.
RCPA3 Package Tutorial Videos
-
Sort and View Case-Level Information with the sortC Function 12:22
-
Complete Playlist of RCPA3 Package Tutorial Videos, includes video for this function and many more.
Textbook References
Philip H. Pollock and Barry C. Edwards, An R Companion to Political Analysis, 3rd Edition (Thousand Oaks, CA: Sage Publications, Forthcoming 2022), Chapters 2, 6.
Philip H. Pollock and Barry C. Edwards, The Essentials of Political Analysis, 6th Edition (Thousand Oaks, CA: Sage Publications, 2020), pp. 122-123. ISBN-13: 978-1506379616; ISBN-10: 150637961.
Online Resources
-
R Tutorials & Resources for Descriptive Statistics, 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.
Examples
library(RCPA3)
# basic usage
sortC(id=state, by=abortlaws, data=states)
# options to limit results and sort in ascending order
sortC(id=country, by=gini.index, descending=FALSE, limit=10, data=world)
# sort by and thenby
sortC(id=country, by=vdem.4cat, thenby=gini.index, descending=c(FALSE, FALSE),
data=world, confirm=FALSE)
sortC(id=country, by=vdem.4cat, thenby=gini.index, descending=c(FALSE, TRUE),
data=world, confirm=FALSE)