This package provides a suite of RKWard plugins that create a
graphical user interface for common and powerful functions from the
popular forcats
R package. It is designed to make factor
manipulation—a common but often tedious task in R—more accessible and
intuitive for RKWard users.
The plugins are designed to seamlessly handle factors that are
standalone vectors, columns in a data frame, or even columns inside
complex list objects (like those from the survey
package).
This package installs a new submenu in RKWard: Data > Factor Tools (forcats), which contains the following five plugins:
fct_infreq()
: Reorder by the frequency of each
level.fct_inorder()
: Reorder by the order in which levels
first appear.fct_inseq()
: Reorder by the numeric value of the
levels.fct_rev()
: Reverse the order of the levels.fct_reorder()
: Reorder a factor by one other
variable.fct_reorder2()
: Reorder a factor by two other
variables.fct_relevel()
fct_shift()
: Cycle the order of levels by a set number
of positions.fct_shuffle()
: Randomize the order of the levels.fct_drop()
A working installation of RKWard.
The R package forcats
. If you do
not have it, install it from the R console:
install.packages("forcats")
The R package devtools
is required
for installation from the source code.
install.packages("devtools")
To install the rk.forcats
plugin package, you need the
source code (e.g., by downloading it from GitHub).
local({
## Preparar
require(devtools)
## Computar
install_github(
repo="AlfCano/rk.forcats"
)## Imprimir el resultado
rk.header ("Resultados de Instalar desde git")
})
Once installed, all plugins can be found under the Data > Factor Tools (forcats) menu in RKWard.
Load the forcats
library and its example dataset
into your R workspace:
library(forcats)
data(gss_cat)
Navigate to Data > Factor Tools (forcats) > Reorder by Property.
The RKWard dialog will open. In the object browser on the left,
you will see the gss_cat
data frame.
Drag the gss_cat
object to the “Factor vector to
reorder” slot on the right. The plugin will automatically detect that
gss_cat
is a data frame and show you its columns.
Select the race
column.
In the “Reordering Method” dropdown, ensure “By frequency” is selected.
In the “Save new factor as” field, you can change the name of the
output object if you wish (e.g., race.reordered
).
Click Submit.
A new object (race.reordered
by default) will be created
in your workspace. If you inspect its levels with
levels(race.reordered)
, you will see that “White”, “Black”,
and “Other” are now ordered by their frequency in the data, not
alphabetically.
Alfonso Cano Robles (alfonso.cano@correo.buap.mx)
Assisted by Gemini, a large language model from Google.