data_transform
Clean and reshape R datasets in a fixed sequence: filter, mutate, recode, convert types, remove missing values and duplicates, arrange/select columns, pivot long/wide. Overwrite or save as new name.
Instructions
Clean and reshape a dataset. Operations run in a fixed order: filter, mutate, to_numeric, recode, to_factor, factor_levels, select, drop, rename, arrange, drop_na, distinct, slice_head, reshape. Writes back to the same name unless save_as is given.
Converting grouping variables to factors is the most common prerequisite for the test tools: to_factor=['group']. Ordered factors for an ordinal outcome need factor_levels={'severity': ['low','medium','high']}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Dataset name in the session. | |
| drop | No | Remove these columns. | |
| filter | No | R logical expression over the columns, e.g. 'age >= 18 & !is.na(score)'. | |
| mutate | No | New/updated columns as {name: R expression}, e.g. {'bmi': 'weight / height^2'}. | |
| recode | No | Value replacement, e.g. {'sex': {'1': 'male', '2': 'female'}}. | |
| rename | No | {new_name: old_name}. | |
| select | No | Keep only these columns. | |
| arrange | No | Sort keys; prefix with '-' for descending. | |
| drop_na | No | Drop rows missing on these columns. | |
| reshape | No | Long/wide conversion. To long: {'direction':'long','value_cols':['t1','t2'],'id_cols':['id'],'names_to':'time','values_to':'score'}. To wide: {'direction':'wide','names_from':'time','values_from':'score','id_cols':['id']}. | |
| save_as | No | Save the result under a new name instead of overwriting. | |
| distinct | No | Remove duplicate rows. | |
| to_factor | No | Columns to convert to factors (needed for grouping variables). | |
| slice_head | No | Keep only the first N rows. | |
| to_numeric | No | Columns to coerce to numeric. | |
| factor_levels | No | Explicit level order, e.g. {'dose': ['low','mid','high']}. Sets the reference level and ordinal order. |