Manually bind new rows to an me data frame

me_bind_metrics(me_data, question_name, metrics)

Arguments

me_data

a data frame of class me

question_name

a character string or a bare unquoted name that will be used as the question name (not a column but a new question appended as row)

metrics

a list containing new metrics. Currently it only supports 'quality', 'reliability' and 'validity'. Can also specify one of the metrics and the remaining are set to 0 by default

Value

me_data with a new row that contains the new question name and the metrics as columns. Metrics must match existing names from SQP data such as 'quality', 'reliability' and 'validity'.

See also

me_construct for the underlying workhorse.

Examples


# Toy dataset
library(tibble)

me_df <-
 tibble(question = paste0("V", 1:5),
 quality = c(0.2, 0.3, 0.5, 0.6, 0.9),
 reliability = c(NA, 0.4, 0.5, 0.5, 0.7),
 validity = c(NA, NA, 0.6, 0.7, 0.8))

me_df <- structure(me_df, class = c(class(me_df), "me"))

me_bind_metrics(me_df, new_question, list(quality = 0.7))
#> # A tibble: 6 × 4
#>   question     quality reliability validity
#>   <chr>          <dbl>       <dbl>    <dbl>
#> 1 V1               0.2        NA       NA  
#> 2 V2               0.3         0.4     NA  
#> 3 V3               0.5         0.5      0.6
#> 4 V4               0.6         0.5      0.7
#> 5 V5               0.9         0.7      0.8
#> 6 new_question     0.7         0        0  
me_bind_metrics(me_df, new_question, list(quality = 0.7, reliability = 0.2))
#> # A tibble: 6 × 4
#>   question     quality reliability validity
#>   <chr>          <dbl>       <dbl>    <dbl>
#> 1 V1               0.2        NA       NA  
#> 2 V2               0.3         0.4     NA  
#> 3 V3               0.5         0.5      0.6
#> 4 V4               0.6         0.5      0.7
#> 5 V5               0.9         0.7      0.8
#> 6 new_question     0.7         0.2      0  

# Specifying a wrong metric name results in error
if (FALSE) {
me_bind_metrics(me_df, new_question, list(wrong_metric = 0.7))
}

# Currently only quality, reliability and validity are allowed.