myop {eye} | R Documentation |
Myopic eye data
Description
Pivot "eye" variable to one column
Usage
myop(x, var = "value")
myopic(x, var = "value")
Arguments
x |
data frame |
var |
Character vector of length 1 specifying the variable if there is only one column per eye with no further info on the variable (default "value") |
Details
Out of convenience, data is often entered in a very "wide" format: there will be two columns for the same variable, one column for each eye. myop will pivot the eye variable to one column and keep all other variables wide. E.g., eight columns that store data of four variables for two eyes will be pivoted to 5 columns (one eye and four further variable columns, see also examples).
myop requires a specific data format
If there is a column called "eye" or "eyes", myop will not make any changes - because the data is then already assumed to be in long format. If you also have columns with eye-specific values, then you have messy data. Maybe, you could remove or rename the "eye" column and then let myop do the work.
myop will only recognize meaningful coding for eyes:
Right eyes: "r", "re", "od", "right"
Left eyes: "l", "le", "os", "left"
for other codes see also eye_codes The strings for eyes need to be separated by period or underscores. (Periods will be replaced by underscores). Any order is allowed.
-
Will work: "va_r", "right_morningpressure", "night_iop.le", "gat_os_postop"
-
Will fail: "VAr", "rightmorningPressure", "night_IOPle", "gatOSpostop"
An exception is when there is only one column for each eye. Then the column names can consist of eye strings (see above) only. In this case, var will be used to "name" the resulting variable.
If there are only eye columns in your data (should actually not happen), myop will create identifiers by row position.
Please always check the result for plausibility. Depending a lot on how the data was entered, the results could become quite surprising. There is basically a nearly infinite amount of possible combinations of how to enter data, and it is likely that myop will not be able to deal with all of them
Value
A tibble, see also tibble::tibble
internal preparation
Rename data names with myop_rename, replacing "." with "_"
Use of
sort_substr()
- sorting eye strings first, then strings coding for methods (IOP/VA), then the rest.
myopization
The actual work is done with myopizer and myop_pivot
Examples
# Example to clean a bit messy data frame
iopva <- data.frame(
id = c("a", "e", "j", "h"),
va_r = c(37L, 36L, 33L, 38L),
iop_r = c(38L, 40L, 33L, 34L),
va_l = c(30L, 39L, 37L, 40L),
iop_l = c(31L, 34L, 33L, 31L)
)
myop(iopva)
iop_wide <- data.frame(id = letters[1:3], r = 11:13 , l = 14:16)
# the variable has not been exactly named, so you can specify
# it with the var argument
myop(iop_wide, var = "iop")