You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R语言中生成表格时如何保持评分量表的原始顺序?

Reordering Likert Scale Table Output in R

The default alphabetical sorting happens because your question1 variable is probably stored as a character vector. To get the table in your desired Likert scale order, you need to convert it to a factor with custom levels defined in the sequence you want.

Here's the step-by-step solution:

  1. First, define your preferred scale order as a character vector:
scale_order <- c("strongly agree", "agree", "neutral", "disagree", "strongly disagree")
  1. Convert question1 to a factor using these levels. This tells R the exact order you want to use for this variable:
question1 <- factor(question1, levels = scale_order)
  1. Now run the table() function again—it will respect your custom level order instead of sorting alphabetically:
table(question1)

This should produce the output you're looking for:

strongly agree          agree        neutral       disagree strongly disagree 
           30            40            45            15             22 

Why this works:

Factors in R have an explicit, user-definable order of levels. When you use table() on a factor, it uses this predefined order to arrange the output, rather than falling back to alphabetical sorting of character values.

If you don't want to modify the original question1 variable (e.g., you still need it as a character vector for other tasks), you can create a temporary factor instead:

temp_likert_factor <- factor(question1, levels = scale_order)
table(temp_likert_factor)

This will give you the same correctly ordered table without altering your original data.

内容的提问来源于stack exchange,提问作者Yubin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 17:53:12