First 10 rows of r
| uuidstring | contentstring | content_formatstring | raw_contentstring | taskstring | analysisstring | solutionstring | teststring | full_contentstring | full_content_formatstring |
|---|---|---|---|---|---|---|---|---|---|
| 9c724570-025a-4d28-8b7c-9c959609380e | # Write an R function that takes a matrix where each column represents a different model complexity level and each row represents a repeated evaluation (e.g., cross-validation fold or bootstrap iteration) of a model selection criterion (such as BIC). The function should also acce… | code comment | calcMaxBasisDim <- function(bicMat, basis_seq = seq(3,51,2)){ optBasisDim <- basis_seq[max(apply(bicMat, 2, which.min))] return(optBasisDim) } |
| Write an R function that takes a matrix where each column represents a different model complexity level and each row represents a repeated evaluation (e.g., cross-validation fold or bootstrap iteration) of a model selection criterion (such as BIC). The function should also accept… |
| The core algorithm works in two steps: first, reduce each column to its minimum value using `apply(bicMat, 2, which.min)` which returns the row index of the first occurrence of the minimum in each column (because `which.min` returns the first index when ties). Then, `max()` is ap… |
| # Return the basis dimension corresponding to the column with the global minimum criterion value. select_optimal_basis_dim <- function(criterion_matrix, basis_seq = seq(3, 51, 2)) { # Validate input dimensions if (ncol(criterion_matrix) != length(basis_seq)) { stop("Numbe… |
| # Test 1: Simple case, global minimum in middle column mat1 <- matrix(c(10, 5, 8, 3, 7, 6), nrow = 2, byrow = TRUE) # Columns: c(10,5), c(8,3), c(7,6) → global min=3 in column 2 → basis_seq[2]=5 stopifnot(identical(select_optimal_basis_dim(mat1), 5L)) # Test 2: Global minimum in… |
| Write an R function that takes a matrix where each column represents a different model complexity level and each row represents a repeated evaluation (e.g., cross-validation fold or bootstrap iteration) of a model selection criterion (such as BIC). The function should also accept… |
| test-first order |
| b22d6289-0555-4e01-86d6-52fa925ed5ca | Write an R function called `evaluate_set_expression` that takes two arguments: a character string representing a set algebra expression using uppercase letters (A, B, C, etc.) as operands and the operators `+` (union), `-` (set difference), and `*` (intersection), along with pare… | no fence | encryptUrlParam <- function(paramStr) { # pubkeyHex <- read_file("public.txt") pubkeyHex <- "42b3781d6907cd426b9c05cac7155cce15bb9385a602716f619529485dab6c28" pubkey <- hex2bin(pubkeyHex) msg <- serialize(paramStr, NULL) ciphertext <- simple_encrypt(msg, pubk… | Write an R function called `evaluate_set_expression` that takes two arguments: a character string representing a set algebra expression using uppercase letters (A, B, C, etc.) as operands and the operators `+` (union), `-` (set difference), and `*` (intersection), along with pare… | The solution involves two main steps: (1) converting the infix expression to postfix notation and (2) evaluating the postfix expression using set operations. **Algorithm Overview:** - **Infix to Postfix Conversion:** Use the standard shunting-yard algorithm. Iterate through eac… | # Evaluate a set algebra expression with + (union), - (difference), * (intersection), # and parentheses, given a named list of sets. Returns the resulting character vector. evaluate_set_expression <- function(expression, set_list) { # --- Helper: Infix to Postfix Conversion (eq… | # Test data sets <- list( A = c("g1", "g2", "g3", "g4"), B = c("g3", "g4", "g5", "g6"), C = c("g5", "g6", "g7", "g8") ) # Test 1: Basic union stopifnot(identical( evaluate_set_expression("A + B", sets), c("g1", "g2", "g3", "g4", "g5", "g6") )) # Test 2: Intersection s… | # Write an R function called `evaluate_set_expression` that takes two arguments: a character string representing a set algebra expression using uppercase letters (A, B, C, etc.) as operands and the operators `+` (union), `-` (set difference), and `*` (intersection), along with pa… | standard order |
| 9e38645d-582c-41a7-9905-bb16d745e14e | Write an R function that takes a data frame containing survey responses (with columns representing individual survey questions on a 0-100 scale) and a named list mapping outcome variables ("Satisfy_score1", "Manager_score", "Belonging_score") to vectors of predictor variable name… | markdown | Sys.setenv(LANG = "en") library(readr) library(dplyr) setwd("C:/Users/choyinch/Downloads/Wellcome_Glint") #Without duplicate data = read.csv("./score_wellcome.csv") newdata = read.csv("./score_wellcome_duplicate.csv") #duplicate--> not use #tdata <-read.csv("./score_wellcome_new.… | Write an R function that takes a data frame containing survey responses (with columns representing individual survey questions on a 0-100 scale) and a named list mapping outcome variables ("Satisfy_score1", "Manager_score", "Belonging_score") to vectors of predictor variable name… | The solution requires a multi-step pipeline: first, for each outcome, split the data into predictors and target, train a random forest, extract importance measures using the `randomForest` package, and compute a combined rank per predictor (sum of percentile ranks for MSE and nod… | # Load required packages library(randomForest) # Build combined importance ranking table for multiple outcomes build_importance_ranking <- function(data, outcome_specs) { # Extract all unique predictor variables all_vars <- unique(unlist(outcome_specs)) # Initialize res… | # Test data generation set.seed(42) test_data <- data.frame( Satisfy_score1 = sample(50:100, 100, replace = TRUE), Manager_score = sample(40:95, 100, replace = TRUE), Belonging_score = sample(45:100, 100, replace = TRUE), avg_score_Q1 = sample(0:100, 100, replace = TRUE),… | # Write an R function that takes a data frame containing survey responses (with columns representing individual survey questions on a 0-100 scale) and a named list mapping outcome variables ("Satisfy_score1", "Manager_score", "Belonging_score") to vectors of predictor variable na… | solution-first order |
| b776f3de-a966-4e13-92e1-58526c0a8379 | Write an R function `process_great_circles` that takes a numeric matrix `poles` with columns representing azimuth (`azi`) and dip (`dip`) of joint pole orientations (degrees), and a character string `file_name`. For each pole, convert it to a great circle plane using the transfor… | no fence | #' plot_joint_great_circles #' #' This function loads joint maxima poles, convert them to great circles and #' plot them on Schmidt stereogram. #' Data are also saved in working folder. #' #' #' @param giac_max Joint maxima poles returned from plot_joint_poles function #' @para… | Write an R function `process_great_circles` that takes a numeric matrix `poles` with columns representing azimuth (`azi`) and dip (`dip`) of joint pole orientations (degrees), and a character string `file_name`. For each pole, convert it to a great circle plane using the transfor… | The solution approach involves vectorized operations for efficiency. First, validate the input matrix: ensure it has at least one row, exactly two columns, numeric values, no NA in azimuth, and dip values within [0,90]. Then compute the transformed plane azimuth using modulo arit… | # Convert joint pole orientations to great circle planes and save them to a file. # Args: # poles: numeric matrix with two columns (azimuth, dip) in degrees. # file_name: character string prefix for output file. # Returns: # Numeric matrix with two columns (Azimuth, Dip) of… | # Test 1: Basic conversion with two poles poles1 <- matrix(c(0, 90, 45, 45), nrow = 2, byrow = TRUE) result1 <- process_great_circles(poles1, "test1") expected1 <- matrix(c(90, 0, 135, 45), nrow = 2, byrow = TRUE, dimnames = list(NULL, c("Azimuth", "Dip"))) s… | Write an R function `process_great_circles` that takes a numeric matrix `poles` with columns representing azimuth (`azi`) and dip (`dip`) of joint pole orientations (degrees), and a character string `file_name`. For each pole, convert it to a great circle plane using the transfor… | commented standard order |
| 5b491538-e640-4712-b42a-35a24fe80793 | # Create an R function called `aggregate_trait_data` that processes a data frame of species trait observations. The input data frame contains columns: `species` (character, possibly with underscores), `trait_value` (numeric, can be NA), `presence` (character: "present"/"absent"),… | code comment | # Section 0: Packages ----------------------------------------------------- library(ape) library(corHMM) library(phangorn) library(stringr) library(here) library(rotl) library(ggtree) library(gsheet) library(dplyr) library(phytools) library(geiger) library(ggplot2) library(rphyl… | Create an R function called `aggregate_trait_data` that processes a data frame of species trait observations. The input data frame contains columns: `species` (character, possibly with underscores), `trait_value` (numeric, can be NA), `presence` (character: "present"/"absent"), a… | The solution requires a two-phase aggregation approach. First, group the data by species and compute summary statistics: median trait value while ignoring NAs, count of observations, and logical indicators for whether any presence is "present" or "absent". The key algorithm follo… | # Aggregate trait observations per species with presence-aware logic aggregate_trait_data <- function(df) { # Load required packages if not already attached if (!requireNamespace("dplyr", quietly = TRUE)) { install.packages("dplyr") } library(dplyr) # Input valid… | # Test 1: Basic aggregation with multiple observations test_df1 <- data.frame( species = c("Species_A", "Species_A", "Species_B"), trait_value = c(2, 4, 1), presence = c("present", "present", "absent") ) result1 <- aggregate_trait_data(test_df1) stopifnot(nrow(result1) == 2… | # Create an R function called `aggregate_trait_data` that processes a data frame of species trait observations. The input data frame contains columns: `species` (character, possibly with underscores), `trait_value` (numeric, can be NA), `presence` (character: "present"/"absent"),… | commented standard order |
| ff99fe32-6803-4164-9989-b5a02dda6fcd | Write an R function called `incidence_from_cumulative` that takes a data.frame with a date column and a cumulative case count column, and returns a data.frame with the same date column and a new column `incidence` containing the daily new cases (the difference between consecutive… | no fence | #' Estimate R(t) from cumulative case time series #' #' Given a case-tracking dataset, determine the basic reproduction #' index over time. #' #' @importFrom EpiEstim make_config estimate_R #' @importFrom dplyr filter %>% #' @importFrom rlang enquo `!!` #' @importFrom R0 esti… | Write an R function called `incidence_from_cumulative` that takes a data.frame with a date column and a cumulative case count column, and returns a data.frame with the same date column and a new column `incidence` containing the daily new cases (the difference between consecutive… | The solution requires a step-by-step transformation of cumulative counts to daily incidence. First, I need to identify the minimum and maximum dates in the input, then create a complete sequence of dates from min to max by day. Using `merge` with `all.x=TRUE`, I combine the full … | # Convert cumulative case counts to daily incidence, filling date gaps with zeros incidence_from_cumulative <- function(df, date_column = "date", cases_column = "count") { # Check if we have enough data to compute incidence if (nrow(df) < 2) { return(data.frame(matrix(nco… | # Test with basic consecutive dates df1 <- data.frame(date = as.Date("2020-01-01") + 0:4, count = c(1, 3, 6, 10, 15)) res1 <- incidence_from_cumulative(df1) stopifnot(identical(res1$incidence, c(1, 2, 3, 4, 5))) stopifnot(identical(res1$date, df1$date)) # Test with date gaps df2… | # Write an R function called `incidence_from_cumulative` that takes a data.frame with a date column and a cumulative case count column, and returns a data.frame with the same date column and a new column `incidence` containing the daily new cases (the difference between consecuti… | commented standard order |
| 65180772-5d00-457c-8c17-930ad9f94df2 | "Write an R function that takes a data frame containing country-level data with columns for `iso3`, | markdown | "# Script for generating the following visulizations related to SDG and Happiness\n# 1. Bar plot of | "Write an R function that takes a data frame containing country-level data with columns for `iso3`, | "The solution begins by validating that the input data frame contains the required columns (`iso3`, | "# Analyze SDG and happiness scores: compute correlation and extract top/bottom countries.\nsdg_happ | "# Test 1: Basic example with 10 countries\ntest_data <- data.frame(\n iso3 = c(\"FIN\", \"SWE\", \ | "# Write an R function that takes a data frame containing country-level data with columns for `iso3` | test-first order |
| e9c4b8ee-065d-440e-a04b-24714c492851 | "Write an R function `create_enzyme` that constructs and returns an `Enzyme` R6 object (as defined i | markdown | "#' Create a new Enzyme\n#'\n#' @description\n#' Enzyme object\n#'\n#' @docType class\n#' @title Enz | "Write an R function `create_enzyme` that constructs and returns an `Enzyme` R6 object (as defined i | "The solution involves creating a wrapper function that instantiates the `Enzyme` R6 class. Since th | "# Load required packages\nlibrary(R6)\nlibrary(jsonlite)\n\n# Define the Enzyme class (as given in | "# Test 1: No arguments returns empty object\nempty_obj <- create_enzyme()\nstopifnot(is.null(empty_ | "Write an R function `create_enzyme` that constructs and returns an `Enzyme` R6 object (as defined i | test-first order |
| 068e6ce3-716f-48ce-b042-c6ef0d9108c8 | "Write an R function called `extract_candidate_info` that takes a character vector containing resume | markdown | "#Function to extract the details of a candidate using regular expressions\nextractInfo <- function( | "Write an R function called `extract_candidate_info` that takes a character vector containing resume | "The solution uses three separate regular expressions to extract the required information from each | "# Extract contact, email, and experience details from resume text.\nextract_candidate_info <- funct | "# Test with a single vector containing all three patterns\ntest_text1 <- \"Phone: 1234567890, email | "# Write an R function called `extract_candidate_info` that takes a character vector containing resu | solution-first order |
| 95574ec7-9964-4b65-9e00-aad36f14e145 | "# Write an R function that computes the clipping function used in robust regression influence curve | code comment | "## generate IC\n## for internal use only!\nsetMethod(\"generateIC\", signature(neighbor = \"ContNei | "Write an R function that computes the clipping function used in robust regression influence curves. | "The task models the influence curve (IC) construction from the given code snippet, focusing on the | "# Generate a list of clipping functions for robust influence curves.\n# Each function takes a numer | "# Test 1: Single element, no d\nf_list <- clip_ic_function(Y = 2, b = 1)\nstopifnot(is.list(f_list) | "Write an R function that computes the clipping function used in robust regression influence curves. | test-first order |