目录
方法解析
python实现
R实现
把题号随机排列,并求得每套试卷所包含的题号和行数
按照随机生成的列数和行数截取试卷
调整试卷题号
完整代码
假设Excel里有500道题目,需要重新随机编排成5套试卷,并且每套试卷里面的题目都不一样。
数据展示:(数据来源:滑动验证页面)
方法解析先把500道题随机排列,然后依次取100道题编排进5套试卷。
(先欠着,哪天想写了再回来写!!!)
R实现 把题号随机排列,并求得每套试卷所包含的题号和行数data=read.csv("D:/CSDN/重新编排试卷/r/测试数据.csv",header = FALSE)
a=sample(1:500,500,replace = FALSE)#把所有题号随机排列
b1=b2=b3=b4=b5=c()#生成题号盒子
for (i in 1:100){
b1=c(b1,a[i])
b2=c(b2,a[100+i])
b3=c(b3,a[200+i])
b4=c(b4,a[300+i])
b5=c(b5,a[400+i])
}
b11=b22=b33=b44=b55=c()#生成行数盒子
k=1:3000
for (i in b1){
for (j in 1:6)
b11=c(b11,k[6*(i-1)+j])
}
for (i in b2){
for (j in 1:6)
b22=c(b22,k[6*(i-1)+j])
}
for (i in b3){
for (j in 1:6)
b33=c(b33,k[6*(i-1)+j])
}
for (i in b4){
for (j in 1:6)
b44=c(b44,k[6*(i-1)+j])
}
for (i in b5){
for (j in 1:6)
b55=c(b55,k[6*(i-1)+j])
}
按照随机生成的列数和行数截取试卷
m1=t(data)#转置
data1=t(subset(m1,select = b11))#按照列数选取子集
data2=t(subset(m1,select = b22))
data3=t(subset(m1,select = b33))
data4=t(subset(m1,select = b44))
data5=t(subset(m1,select = b55))
调整试卷题号
for (i in 1:100){
data1[6*(i-1)+1]=gsub(b1[i],i,data1[6*(i-1)+1])
data2[6*(i-1)+1]=gsub(b2[i],i,data2[6*(i-1)+1])
data3[6*(i-1)+1]=gsub(b3[i],i,data3[6*(i-1)+1])
data4[6*(i-1)+1]=gsub(b4[i],i,data4[6*(i-1)+1])
data5[6*(i-1)+1]=gsub(b5[i],i,data5[6*(i-1)+1])
}
接着把试卷导出就可以实现完整的试卷编排 *** 作了!!!
接着还可以实现无答案的试卷编排,只需要修改部分代码为:
for (i in b1){
for (j in c(1:5))
b11=c(b11,k[6*(i-1)+j])
}
完整代码
data=read.csv("D:/CSDN/重新编排试卷/r/测试数据.csv",header = FALSE)
a=sample(1:500,500,replace = FALSE)#把所有题号随机排列
b1=b2=b3=b4=b5=c()#生成题号盒子
for (i in 1:100){
b1=c(b1,a[i])
b2=c(b2,a[100+i])
b3=c(b3,a[200+i])
b4=c(b4,a[300+i])
b5=c(b5,a[400+i])
}
b11=b22=b33=b44=b55=c()#生成行数盒子
k=1:3000
for (i in b1){
for (j in 1:6)
b11=c(b11,k[6*(i-1)+j])
}
for (i in b2){
for (j in 1:6)
b22=c(b22,k[6*(i-1)+j])
}
for (i in b3){
for (j in 1:6)
b33=c(b33,k[6*(i-1)+j])
}
for (i in b4){
for (j in 1:6)
b44=c(b44,k[6*(i-1)+j])
}
for (i in b5){
for (j in 1:6)
b55=c(b55,k[6*(i-1)+j])
}
m1=t(data)#转置
data1=t(subset(m1,select = b11))#按照列数选取子集
data2=t(subset(m1,select = b22))
data3=t(subset(m1,select = b33))
data4=t(subset(m1,select = b44))
data5=t(subset(m1,select = b55))
for (i in 1:100){
data1[6*(i-1)+1]=gsub(b1[i],i,data1[6*(i-1)+1])
data2[6*(i-1)+1]=gsub(b2[i],i,data2[6*(i-1)+1])
data3[6*(i-1)+1]=gsub(b3[i],i,data3[6*(i-1)+1])
data4[6*(i-1)+1]=gsub(b4[i],i,data4[6*(i-1)+1])
data5[6*(i-1)+1]=gsub(b5[i],i,data5[6*(i-1)+1])
}
#无答案抽取修改
for (i in b1){
for (j in c(1:5))
b11=c(b11,k[6*(i-1)+j])
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)