1

I notice that the logic of using x1 %to% x8 in R seems not consistent. Sometimes all variables physically located between the variables in the dataset are used (cfr. SPSS),

d%>%tab_cols(total()) %>%
  tab_cells (mdset(Q20_01_more %to% Q20_03_more)) %>%
  tab_stat_cases(total_row_position = c("none"),label = 'N') %>%
  tab_stat_cpct(total_row_position = c("none"), label = '%') %>%
  tab_pivot (stat_position = "inside_rows") %>%  
  #drop_c ()  %>%
  recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)   %>%
  custom_format2()  %>%
  set_caption("test")

produces the tabel below containing the 3 variables stored in consecutive columns in dataframe 'd'

enter image description here

other times it seems that R sorts all variables based on the variable names and evaluates all variables appearing between both in the sort.

> names_totaln<-names(eval(substitute(Q20_01_more %to% Q20_03_more),d))
> names_totaln
[1] "Q20_01_more" "Q20_02"      "Q20_02_less" "Q20_02_more" "Q20_03"      "Q20_03_less"
[7] "Q20_03_more"

Any advice on how to use correctly?

Tx!

  • 1
    `%to%` is not a base R function. What package are you using where it's defined? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Mar 26 '21 at 18:00

1 Answers1

0

The issue here is that when you call eval , '%to%' unawared about order of variable and just use alphabetic order. There is a set of functions in the expss package which give information about variable order: compute, do_if, calc and tab_*. You can easily get help about them by typing ?compute in the console. Your last expression with calc:

names_totaln<-names(eval(substitute(calc(d, Q20_01_more %to% Q20_03_more))))
names_totaln
Gregory Demin
  • 4,596
  • 2
  • 20
  • 20