myop: Myopic eye data

Description Usage Arguments Details Value internal preparation myopization Examples

View source: R/myop.R

Description

Pivot "eye" variable to one column

Usage

1
2
3
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:

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

myopization

The actual work is done with myopizer and myop_pivot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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")

Example output

# A tibble: 8 x 4
  id    eye   va    iop  
  <chr> <chr> <chr> <chr>
1 a     r     37    38   
2 a     l     30    31   
3 e     r     36    40   
4 e     l     39    34   
5 j     r     33    33   
6 j     l     37    33   
7 h     r     38    34   
8 h     l     40    31   
# A tibble: 6 x 3
  id    eye   iop  
  <chr> <chr> <chr>
1 a     r     11   
2 a     l     14   
3 b     r     12   
4 b     l     15   
5 c     r     13   
6 c     l     16   

eye documentation built on Sept. 5, 2021, 5:25 p.m.