我想知道如何将主题划分为4个不同的范围/级别。每个级别都有一定的范围。以下是数据。
Std Name Subject Percentage
2 Vinay eng 50
2 Vinay math 60
2 Vinay hindi 70
2 Rohan eng 70
2 vas mat 50
2 dheer eng 35
2 dheer math 90
2 dheer hindi 80
2 Bhas eng 90
2 Bhas math 35
2 Bhas hindi 50
四个铲斗范围如下。 < = 35,35-50,50-75,> 75
预期产出:
Std Subject 0-35 35-50 50-75 >75
2 Eng 25% 25% 25% 25%
2 Mat 25% 25% 25% 25%
2 Hin 0% 25% 25% 25%
P.s范围的值是在该范围内得分的学生百分比。
提前致谢
答案 0 :(得分:0)
这应该有效,也许可以为结构化做一些工作:
df<-read.table(header = TRUE, sep=",", text="Std, Name, Subject, Percentage
2, Vinay,eng, 50
2, Vinay,math, 60
2, Vinay,hindi, 70
2, Rohan,eng, 70
2, vas,math, 50
2, dheer,eng, 35
2, dheer,math, 90
2, dheer,hindi, 80
2, Bhas,eng, 90
2, Bhas,math, 35
2, Bhas,hindi, 50")
breaks<-c(0, 35, 50, 75, 100)
t<-table(df$Subject, responseName=cut(df$Percentage, breaks = breaks) )
format(t/rowSums(t), digits=3)
答案 1 :(得分:0)
可能的data.table解决方案:
var Objects = require('objects.js'); new Objects.ObjDefElsewhere();