R 使用公式对问卷调查对象进行评分
编制了一份包含多个单项选择问题的问卷,对受访者进行评分。每个问题的选择最初都会被打分。初始分数可能会改变,但与问题无关。下面显示的R 使用公式对问卷调查对象进行评分,r,plyr,R,Plyr,编制了一份包含多个单项选择问题的问卷,对受访者进行评分。每个问题的选择最初都会被打分。初始分数可能会改变,但与问题无关。下面显示的值列反映了该初始分数 我想使用加权问题的公式对受访者进行评分。由于公式可能会改变以反映不同的评估标准,因此自然选择一种更通用的评分方法 简单示例 structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c("Ind_1", "Ind_2"), class =
值
列反映了该初始分数
我想使用加权问题的公式对受访者进行评分。由于公式可能会改变以反映不同的评估标准,因此自然选择一种更通用的评分方法
简单示例
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Ind_1", "Ind_2"), class = "factor"),
question = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L),
.Label = c("Q1", "Q2", "Q3", "Q4", "Q5"), class = "factor"),
value = c(1L, 1L, 3L, 2L, 5L, 1L, 2L, 3L, 2L, 4L)),
.Names = c("id", "question", "value"),
class = "data.frame", row.names = c(NA, -10L))
id scored_value
Ind_1 12.50
Ind_2 13.17
表示这一点:
id question value
Ind_1 Q1 1
Ind_1 Q2 1
Ind_1 Q3 3
Ind_1 Q4 2
Ind_1 Q5 5
Ind_2 Q1 1
Ind_2 Q2 2
Ind_2 Q3 3
Ind_2 Q4 2
Ind_2 Q5 4
公式:
这是对受访者进行评分的公式
2*((Q1+ 1.5*Q2)/2) + 2.5*((Q3+(2*Q4)+Q5)/3)
预期结果
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Ind_1", "Ind_2"), class = "factor"),
question = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L),
.Label = c("Q1", "Q2", "Q3", "Q4", "Q5"), class = "factor"),
value = c(1L, 1L, 3L, 2L, 5L, 1L, 2L, 3L, 2L, 4L)),
.Names = c("id", "question", "value"),
class = "data.frame", row.names = c(NA, -10L))
id scored_value
Ind_1 12.50
Ind_2 13.17
希望这足够清楚可能有更好的答案。首先,我使用
reformae2
包将数据从长到宽进行了转换。然后,我使用plyr
包计算得分值
foo <- read.table(text="id question value
Ind_1 Q1 1
Ind_1 Q2 1
Ind_1 Q3 3
Ind_1 Q4 2
Ind_1 Q5 5
Ind_2 Q1 1
Ind_2 Q2 2
Ind_2 Q3 3
Ind_2 Q4 2
Ind_2 Q5 4", header=TRUE)
library(reshape2)
# convert from long to wide
bar <- dcast(foo, id ~ question)
library(plyr)
# for each id, compute the scored value
baz <- ddply(bar, .(id), summarise, scored_value=2*((Q1+ 1.5*Q2)/2) + 2.5*((Q3+(2*Q4)+Q5)/3))
foo可能有更好的答案。首先,我使用reformae2
包将数据从长到宽进行了转换。然后,我使用plyr
包计算得分值
foo <- read.table(text="id question value
Ind_1 Q1 1
Ind_1 Q2 1
Ind_1 Q3 3
Ind_1 Q4 2
Ind_1 Q5 5
Ind_2 Q1 1
Ind_2 Q2 2
Ind_2 Q3 3
Ind_2 Q4 2
Ind_2 Q5 4", header=TRUE)
library(reshape2)
# convert from long to wide
bar <- dcast(foo, id ~ question)
library(plyr)
# for each id, compute the scored value
baz <- ddply(bar, .(id), summarise, scored_value=2*((Q1+ 1.5*Q2)/2) + 2.5*((Q3+(2*Q4)+Q5)/3))
foo可能有更好的答案。首先,我使用reformae2
包将数据从长到宽进行了转换。然后,我使用plyr
包计算得分值
foo <- read.table(text="id question value
Ind_1 Q1 1
Ind_1 Q2 1
Ind_1 Q3 3
Ind_1 Q4 2
Ind_1 Q5 5
Ind_2 Q1 1
Ind_2 Q2 2
Ind_2 Q3 3
Ind_2 Q4 2
Ind_2 Q5 4", header=TRUE)
library(reshape2)
# convert from long to wide
bar <- dcast(foo, id ~ question)
library(plyr)
# for each id, compute the scored value
baz <- ddply(bar, .(id), summarise, scored_value=2*((Q1+ 1.5*Q2)/2) + 2.5*((Q3+(2*Q4)+Q5)/3))
foo可能有更好的答案。首先,我使用reformae2
包将数据从长到宽进行了转换。然后,我使用plyr
包计算得分值
foo <- read.table(text="id question value
Ind_1 Q1 1
Ind_1 Q2 1
Ind_1 Q3 3
Ind_1 Q4 2
Ind_1 Q5 5
Ind_2 Q1 1
Ind_2 Q2 2
Ind_2 Q3 3
Ind_2 Q4 2
Ind_2 Q5 4", header=TRUE)
library(reshape2)
# convert from long to wide
bar <- dcast(foo, id ~ question)
library(plyr)
# for each id, compute the scored value
baz <- ddply(bar, .(id), summarise, scored_value=2*((Q1+ 1.5*Q2)/2) + 2.5*((Q3+(2*Q4)+Q5)/3))
foo谢谢,这一切正常。我没有想到使用铸造我的熔化的格式化表。谢谢这是预期的工作。我没有想到使用铸造我的熔化的格式化表。谢谢这是预期的工作。我没有想到使用铸造我的熔化的格式化表。谢谢这是预期的工作。我没能用石膏思考我的桌子。