diff --git a/DESCRIPTION b/DESCRIPTION index f15ef04..75a6976 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,8 +2,8 @@ Encoding: UTF-8 Package: rkTeaching Type: Package Title: A RKWard plugin with basic utilities for teaching Statistics -Version: 1.3.0 -Date: 2019-09-01 +Version: 1.3.5 +Date: 2022-17-13 Author: Alfredo Sánchez Alberca Maintainer: Alfredo Sánchez Alberca Enhances: rkward @@ -21,6 +21,7 @@ Depends: Hmisc, prob, ez, + multcomp, R (>= 3.5.0) Description: Basic utilities for teaching statistics. It contains procedures for: diff --git a/R/weightDataFrame.R b/R/weightDataFrame.R index 59951da..65fe4b0 100644 --- a/R/weightDataFrame.R +++ b/R/weightDataFrame.R @@ -1,13 +1,11 @@ weightDataFrame <- function(data, freq){ - if (ncol(data)<2) { - stop("The data frame must contain at least two variables.") - } - if (!is.numeric(data[["freq"]])) { - stop("The freq variable should contain frequencies and must be numeric.") - } - times <- as.integer(data[[freq]]) - data[[freq]] <- NULL - result <- data[rep(seq_len(nrow(data)), times),] + reps <- data[[freq]] + data[[freq]] <- NULL + m <- as.matrix(data) + result <- as.vector(m) + result <- matrix(rep(result,rep(reps,ncol(m))),sum(reps),ncol(m)); + result <- as.data.frame(result); + colnames(result) <- colnames(data) return(result) } diff --git a/inst/rkward/plugins/common/common_functions.js b/inst/rkward/plugins/common/common_functions.js index ab5a424..d989625 100644 --- a/inst/rkward/plugins/common/common_functions.js +++ b/inst/rkward/plugins/common/common_functions.js @@ -3,6 +3,6 @@ function getDataframe(vars) { if (Array.isArray(vars)) { return vars.join().split('[[')[0]; } else { - return vars.split('[[')[0]; + return vars.toString().split('[[')[0]; } } diff --git a/inst/rkward/plugins/data/data_weighting.js b/inst/rkward/plugins/data/data_weighting.js index 79611e5..b08ced5 100644 --- a/inst/rkward/plugins/data/data_weighting.js +++ b/inst/rkward/plugins/data/data_weighting.js @@ -1,23 +1,26 @@ // author: Alfredo Sánchez Alberca (asalber@ceu.es) -var dataframe, - freq, - newDataframe; -function setGlobalVars() { - dataframe = getString("dataframe"); - freq = getString("freq.shortname"); - newDataframe = getString("newDataframe"); -} +// globals +var data, newdata, freq; -function preprocess() { - setGlobalVars(); - echo("library(rkTeaching)\n"); +function preprocess(){ + // add requirements etc. here + echo("require(rkTeaching)\n"); } -function calculate() { - echo('.GlobalEnv$' + newDataframe + ' <- weightDataFrame(' + dataframe + ', "' + freq + '")\n'); +function calculate () { + data = getString("dataframe"); + newdata = getString("save"); + freq = getString("freq.shortname"); + echo ('.GlobalEnv$' + newdata + ' <- weightDataFrame(' + data + ', "' + freq + '")\n'); + // Copy also the labels of original data set + echo('for(i in 1:length(names(' + newdata + '))){\n'); + echo('\t if (names(' + newdata + ')[i]!= "' + freq + '"){\n'); + echo('\t attr(.GlobalEnv$' + newdata + '[[names(' + newdata + ')[i]]],".rk.meta") = attr(' + data + '[[names(' + newdata + ')[i]]],".rk.meta")\n'); + echo('\t }\n'); + echo('}\n'); } -function printout() { - var header = new Header(i18n("Data weighting")).addFromUI("dataframe").addFromUI("freq").addFromUI("newDataframe").print(); +function printout () { + echo ('rk.header ("Ponderación de conjunto de datos", parameters=list("Conjunto de datos a ponderar" = "' + data + '", "Frecuencias de ponderación" = "' + freq + '", "Nuevo conjunto de datos" = rk.get.description(' + newdata + ')))\n'); } diff --git a/inst/rkward/plugins/data/data_weighting.xml b/inst/rkward/plugins/data/data_weighting.xml index fc79a0d..efce73d 100644 --- a/inst/rkward/plugins/data/data_weighting.xml +++ b/inst/rkward/plugins/data/data_weighting.xml @@ -6,43 +6,45 @@ - - - - - - - - - + + + + + + + - - - + + + - - - + + + - Select the data frame to weight. + Seleccionar el conjunto de datos a ponderar. + - - + + - + - Select the variable that contains the weighting frequencies. + Seleccionar la variable que contiene las frecuencias de ponderación. + Debe haber tantas frecuencias como filas tenga el conjunto de datos a ponderar. + - + - + - Enter the name for the new data set. By default the new data set is saved in the .GlobalEnv environment. + Introducir un nombre para el nuevo conjunto de datos. + Por defecto el nuevo conjunto de datos se guarda en el espacio de trabajo global .GlobalEnv. + - - + diff --git a/inst/rkward/plugins/data/variable_recoding.js b/inst/rkward/plugins/data/variable_recoding.js index 2e07224..400cc72 100644 --- a/inst/rkward/plugins/data/variable_recoding.js +++ b/inst/rkward/plugins/data/variable_recoding.js @@ -19,11 +19,11 @@ function calculate() { rules = rules.replace(/\n/gi, '; ').replace(/'/g, '"'); comment("Applying the recoding rules"); echo(".GlobalEnv$" + save + " <- Recode(" + variable + ", '" + rules + "'"); - if (asfactor) { - echo(", as.factor=TRUE"); - } else { - echo(", as.factor=FALSE"); - } + //if (asfactor) { + // echo(", as.factor=TRUE"); + //} else { + // echo(", as.factor=FALSE"); + //} echo(")\n"); } diff --git a/inst/rkward/plugins/non_parametric_tests/kruskal_wallis.js b/inst/rkward/plugins/non_parametric_tests/kruskal_wallis.js index 631783c..f4b31cb 100644 --- a/inst/rkward/plugins/non_parametric_tests/kruskal_wallis.js +++ b/inst/rkward/plugins/non_parametric_tests/kruskal_wallis.js @@ -56,7 +56,7 @@ function printout() { // Header header = new Header(i18n("Kruskal-Wallis test for comparing the distribution of %1 according to %2", variableName, factorName)); header.add(i18n("Data frame"), dataframe); - header.add(i18n("Comparison of %1 according to %2", variableName, factorName)); + header.add(i18n("Comparison of"), i18n("%1 according to %2", variableName, factorName)); header.add(i18n("Null hypothesis"), i18n("There is no significant difference between the populations")); header.add(i18n("Alternative hypothesis"), i18n("There are significant difference between at least two populations")); if (grouped) { @@ -104,4 +104,4 @@ function printout() { echo('))\n'); } } -} \ No newline at end of file +}