'Descriptive statistics for ranked choice data frame

I have been hustling with an issue that should be easy to figure out and need help. There are four ranked choice variables V1, V2, V3, V4 in my dataset dtst.

    <chr> <chr>  <chr>  <chr> 
1      1    3      1      2   
2      3    5      4      1   
3      2    1      2      5  
4      5    3      3      3   
5      4    2      5      4 

I need to summarize what is the second most popular choice per each variable. I have mostly been trying to use the package "pmr" to do it.

rankings<-data.frame(dtst[, 1:4])
rankings_agg<-rankagg(rankings)

After I try running the next destat command, it prints an error.

rankings_st<-destat(rankings_agg)

I am not sure it is even the way to go for my task. I need to build some table with pairwise comparisons basically. Thanks.

r


Solution 1:[1]

Do you need something like this:

library(dplyr)

df %>% 
  slice(2) %>% 
  pivot_longer(
    everything(),
    names_to = "Variable", 
    values_to = "Top_2"
  )
  Variable Top_2
  <chr>    <int>
1 V1           3
2 V2           5
3 V3           4
4 V4           1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TarJae