Search code examples
rexpss

How do you compare means row-wise for the same ratings object in the R expss package?


I have repeated measures data with two ratings (reliable and fast) repeated on two different objects, (each survey respondent rates each object using the same two ratings measures). I would like to have two columns, one for object 1 and one for object 2, with the ratings displayed in two separate rows.

In the reference manual there is reference to using a | separator to compare two variables, but the example given is for mrsets not means, I'm not sure how to do the same with means and keep them in separate data frame columns.

In the code below, the problem is that instead of placing the means side by side (for comparison) they are stacked on top of each other.

#library
library(expss)
library(magrittr)

#dummy data
set.seed(9)
df <- data.frame(
q1_reliable=sample(c(1,5), 100, replace = TRUE),
q1_fast=sample(c(1,5), 100, replace = TRUE),
q2_reliable=sample(c(1,5), 100, replace = TRUE),
q2_fast=sample(c(1,5), 100, replace = TRUE))


#table 
df %>%
tab_cells(q1_reliable,q1_fast) %>%
tab_stat_mean(label = "")  %>%
tab_cells(q2_reliable,q2_fast) %>%
tab_stat_mean(label = "")  %>%
tab_pivot()

Solution

  • I discovered that if I add variable labels first and use 'tab_pivot(stat_position = "inside_columns")' it solved the problem.

    #library
    library(expss)
    library(magrittr)
    
    #dummy data
    set.seed(9)
    df <- data.frame(
    q1_reliable=sample(c(1,5), 100, replace = TRUE),
    q1_fast=sample(c(1,5), 100, replace = TRUE),
    q2_reliable=sample(c(1,5), 100, replace = TRUE),
    q2_fast=sample(c(1,5), 100, replace = TRUE)
    )
    
    #labels
    df = apply_labels(df,
    q1_reliable = "reliable",
    q1_fast = "fast",
    q2_reliable = "reliable",
    q2_fast = "fast")
    
    #table
    df %>%
    tab_cells(q1_reliable,q1_fast) %>%
    tab_stat_mean(label = "")  %>%
    tab_cells(q2_reliable,q2_fast) %>%
    tab_stat_mean(label = "")  %>%
    tab_pivot(stat_position = "inside_columns")