Mice function not getting data columns to impute
When I try to impute missing values for my data, the mice function will not pick up the columns that has missing values. I am trying to replace the null values in BusinessTravel but using the below...
View ArticleR - Summarizing percentage by subgroups
I don't know how to explain my problem, but I want to summarize the categories distance and get the percentage for each distance per month. In my tabel 1 week is 100% and now I want to calculate the...
View ArticleError in Repeat Loop - if/else statement problem
I'm trying to find the highest Fibonacci number before 5000. this is the code I have so far:n <- 5000 fib <- c() fib[1] <- 1 fib[2] <- 1 c <- 1 i <- 3 repeat { fib[i] <- fib[i-1] +...
View ArticleFastest way to take difference of elements in a data.frame in R
Using the following dataset, what is the fastest way to compute for each ID (Col1) the difference with all the other ID02 (Col2) within the same time (Col3, t) without using dplyr, (data.table...
View ArticleWierd Residuals in statsmodel SARIMAX function
DATA: https://github.com/AileenNielsen/TimeSeriesAnalysisWithPython/blob/master/data/AirPassengers.csvSo when using statsmodelsarimax in PYTHON function I recieve very strange result in term of...
View ArticleHow do I rotate a plot clockwise with ggplot? [duplicate]
This question already has an answer here:Order Bars in ggplot2 bar graph 12 answersI'm trying to visualize the different backgrunds of our students, the bars represent different high school programs. I...
View ArticleWrong fill in a ggplot RStudio
Using ggplot(adult) + aes(x=as.numeric(age), group=sex, fill=sex) + geom_histogram(binwidth=1, color='black') I get the following chart. However, this is incorrect as the graph is wrongly colouring in...
View ArticleModify global environment when rendering RMarkdown document
Consider this minimal RMarkdown example, saved in the file test.rmd:```{r} foo <- "bar" ``` If you render this file with rmarkdown::render("test.rmd"), the object foo will be found in your global...
View ArticleTrying to find the number of diagonals of 1 in each 3x3 tile in multiple...
I am trying to find the count of diagonal 1s in each 3x3 tile e.g.0 0 1 1 0 0 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 0 1 0 1 0 0 or 0 0 1 or 1 1 1 or 1 0 0 just for example where it doesn't matter about the...
View ArticleFastest way to map multiple character columns to numerical values
I have an algorithm that at each iteration calculates means for certain groups (the groups do not change only their values). The table of the values - d1 <- data.frame(x = sample(LETTERS, N, replace...
View ArticleFitting to a sum of random variables in JAGS (R)
So I currently have a model that is fitting to some 'number of trials where reply is yes'You don't really need to know the details I believe but it's a hierarchical model where the data is a 3d array...
View ArticleSwitching background in markdown beamer
I'm trying to transfer a LaTeX/LyX presentation into a Beamer markdown document.On some slides I suspend the background image (which has logos of funding bodies on it) to make more space for code...
View ArticleSplit into column treating successive delimiters as one
Hi I would like to split one column of a data.frame into multiple columns but with successive delimiters treated as one. My input has been scraped from a text file so is a bit of a mess with different...
View ArticleHow to obtain different maturities from a yield curve
I have a code for the construction of the yield curve, but I kinda want to extract the yields for every 0.25 months. I don't know, where to change it in the code. If extract the variables y1, y2 and y3...
View Articleapplying a rolling error function using rollapply
I am trying to calculate a rolling error function in R where I take the last 30 days and compute the rmse, move forward 1 day and take the last 30 days from this point and compute the new rmse.My data...
View ArticleCan not choose number of periods for forecasting any other than variable length
I want to predict a time series from a model I estimate with tslm from the forecast package. Here is some data:x <- ts(rnorm(120,0,3) + 1:120 + 20*sin(2*pi*(1:120)/12), frequency=12, start= c(2000,...
View ArticleKeep records before and after a specific timestamp
Having a data frame which provides a specific timestampdframe1 <- structure(list(id = c(1L, 1L, 1L, 2L, 2L), name = c("Google", "Yahoo", "Amazon", "Amazon", "Google"), date = c("2008-11-01",...
View ArticleChange background in R Markdown beamer presentation
I'm writing on a beamer presentation in rmarkdown and I have two types of frames which should differ by their background. So I wrote two functions like that in latex:\newcommand{\settitlestyle}{...
View Articleggplot with 2 y axes on each side and different scales
I need to plot a bar chart showing counts and a line chart showing rate all in one chart, I can do both of them separately, but when I put them together, I scale of the first layer (i.e. the geom_bar)...
View ArticleGetting word count of doc/docx files in R
I have a stream of doc/docx documents that I need to get the word count of.The procedure so far is to manually open the document and write down the word count offered by MS Word itself, and I am trying...
View Article