Monty Hall game in R with base functions
Just for fun and to train R, I tried to proof the Monty Hall Game rule (changing your choice after one gate opened gives you more probability to win), I made this reproducible code (The explanation of...
View ArticleMutate Next unique values in one hour and expand and aggregate
I am trying to achieve an sliding window aggregation. I tried something using tidyr functions but I am sure there are much better / faster ways to achieve.Let me explain what I want to achieve:I have...
View ArticleMost efficient way to calculate function with large number of parameter...
Minimalist example of what I'm trying to do:dX_i <- rnorm(100, 0, 0.0002540362) p_vec <- seq(0, 1, 0.25) gamma_vec <- seq(1, 2, 0.25) a_vec <- seq(2, 6, 1) sigma_hat_vec <- c(0.03201636,...
View ArticleSave variable labels in R so that STATA can read them
I have a dataset with over 170 variables that looks as follows:df <- data.frame(var1 = 1:3, var2 = 2:4, var3 = 2:4, var4 = 2:4, var5 = 2:4) I have manually added variable values using...
View ArticleIs there an R function that allows to extract and save coordinates from an...
I have a .xml about flood risk maps in Europe from which I should extract the coordinates and match them with my observations (other coordinates) in order to create dummy variables. Can anyone...
View Articlehow to store the printed output from a function as a vector in R?
I have the following column from a dataframedf <- data.frame( crime = as.character(c(115400, 171200, 91124, 263899, 67601, 51322)), stringsAsFactors=FALSE ) I am using a function to extract the...
View ArticleR vectorize comparison to lists of start and end vectors, respectively
I have:a dataframe DATA containing many numeric columns with the names: X1, X2, X3, ... (the number of columns is variable)numeric vectors start1, start2, start3, ... (as many as the columns of DATA)...
View Articleadding points to raster plots with facets
I have a few raster plots separated with facets. In each plot, I want to add an independent point. This shows how to add a point but I can only add the same point to all plots.Suppose I want to add a...
View ArticleCalculate correlation with cor(), only for numerical columns
I have a dataframe and would like to calculate the correlation (with Spearman, data is categorical and ranked) but only for a subset of columns. I tried with all, but R's cor() function only accepts...
View ArticleHow to export a dataset to SPSS?
I want to export a dataset in the MASS package to SPSS for further investigation. I'm looking for the EuStockMarkets data set in the package.As described in...
View ArticleHow to add Newline in the detail message of a Shiny Progress bar?
Is there any way to write add a newline character in a Shiny Progress bar message? \n or <br> does not seem to work. I am trying to convert one of my old codes into a shiny app. The code...
View ArticleRemove specific string
I would like to remove this characterc("I use thisdf <- gsub("c/(/"", "", df$text) But I receive this error:Error: unexpected string constant in "inliwc <- gsub("c/(/"", ""What can I do?
View Articletidy evaluation in tidyr
This is a question about the codes in vignette("in-packages")The dataset is below.(mini_iris <- iris %>% as_tibble() %>% .[c(1, 2, 51, 52, 101, 102), ]) #> # A tibble: 6 x 5 #>...
View ArticleHow do I fix this Error in R: [.data.frame(newdata, , object$method$center,...
I am trying to recreate a random forest model from a paper, and the code doesnt seem to work, i am only just learning R and this is very much over my head, but i will try to explain as best I can.The...
View ArticleHow to conduct a nested ANOVA
An example of my data is at the bottom of this post. I have collected data on 216 individuals. I measured the concentration of the same 7 Substances in each individual, represented by Sub1:Sub7. The...
View ArticleHow to operator join two matrix in raku-lang?
Is there have something like R-lang columnbind or rowbind in raku. R-lang cbinde.g.my @matrix = ^100 .rotor(10); my @cbind = cbind( @matrix [*;1..2].rotor(2) , @matrix [*;3..4].rotor(2) ) my @rbind =...
View Articleencode special characters in R
My dataset contains a lot of surnames. Those surnames are written with umlauts as well as other special characters (such as č,á,ñ, etc.).By reading the data in the following way (using encoding =...
View ArticleR auto compute features log and poly data matrix
BackgroundI'm writing my own function. The function takes a dataframe input with unfixed number of features. Also, the features' type maybe different,i.e. numeric,factor and chr. I want to maximise my...
View ArticleFind year in random data in R
I have 71 columns in a dataframe, 10 of which include data that may include a year between 1990 and 2019 in the format YYYY (e.g. 2019). For example:id_1 <- c("regkfg_2013", "fsgdf-2014",...
View ArticleNot Being Able to Access 'caret' in 'diamonds' [R, object 'caret' not found]...
I'm learning R for the first time and I am working with boxplots. I want to have some of the box plots filled if they meet a condition. I am using 'diamonds' a general dataset from base R to generate...
View Article