From 6406b4ade367aca7985a6d5c9500126243bc2a44 Mon Sep 17 00:00:00 2001 From: Simon Pintarelli Date: Tue, 22 Aug 2017 19:32:53 +0200 Subject: [PATCH] bugfix (float comparison) - allow point increments to be arbitrary (for example 0.01) - "sane" point increments as 0.25, 0.5, 1,... were not affected by this bug --- statistics.Rnw | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/statistics.Rnw b/statistics.Rnw index 5a13998..3a8c109 100644 --- a/statistics.Rnw +++ b/statistics.Rnw @@ -141,13 +141,18 @@ dset$value <- as.numeric(dset$value) total_points <- group_by(dset, Number) %>% summarize(s=sum(value)) linscale <- data.frame(approx(int_points, int_grades, seq(0, maxpoints, by=dp))) -scale <- data.frame(grade=floor(linscale$y*1/dg)*dg, s=linscale$x) -grades <- data.frame(left_join(x=total_points, y=scale, by="s")) +FUZZY <- 1e6 +linscale$jj <- as.integer(round(linscale$x*FUZZY)) +scale <- data.frame(grade=floor(linscale$y*1/dg)*dg, jj=linscale$jj) +total_points$jj <- as.integer(round(total_points$s*FUZZY)) +grades <- data.frame(left_join(x=total_points, y=scale, by="jj")) +grades <- grades[,c("Number", "s", "grade")] colnames(grades) <- c("legi", "points", "grade") grades$legi <- as.factor(grades$legi) ## plot grading scale (linear interpolation and projection to existing marks) scale_plot <- cbind(linscale, col=rep("linear interpolation", nrow(linscale))) -colnames(scale_plot) <- c("s", "grade", "col") +colnames(scale_plot) <- c("s", "grade", "jj", "col") +scale$s <- scale$jj/FUZZY scale_plot <- rbind(scale_plot, cbind(scale, col=rep("rounded", nrow(linscale)))) @ -- 2.24.1