Find all date ranges for overlapping start and end dates in R

Issue I have a data frame that looks like this: w<-read.table(header=TRUE,text=” start.date end.date 2006-06-26 2006-07-24 2006-07-19 2006-08-16 2007-06-09 2007-07-07 2007-06-24 2007-07-22 2007-07-03 2007-07-31 2007-08-04 2007-09-01 2007-08-07 2007-09-04 2007-09-05 2007-10-03 2007-09-14 2007-10-12 2007-10-19 2007-11-16 2007-11-17 2007-12-15 2008-06-18 2008-07-16 2008-06-28 2008-07-26 2008-07-11

Continue reading

R – Alter the order of a table

Issue I have this dataset structure(list(Data = structure(c(18750, 18750, 18750, 18750, 18751, 18751, 18751, 18753, 18753, 18753), class = "Date"), `Retorno D` = c(NA, NA, NA, NA, "211.52430499997001", "134.38776799989901", "361.888238000218", "180.13891600002501", "100.33839799999301", "211.93803400010799" ), `Retorno D-1` = c("99.984314000001206", "361.888238000218", "178.550884000026",

Continue reading

R – Alter the order of a table

Issue I have this dataset structure(list(Data = structure(c(18750, 18750, 18750, 18750, 18751, 18751, 18751, 18753, 18753, 18753), class = "Date"), `Retorno D` = c(NA, NA, NA, NA, "211.52430499997001", "134.38776799989901", "361.888238000218", "180.13891600002501", "100.33839799999301", "211.93803400010799" ), `Retorno D-1` = c("99.984314000001206", "361.888238000218", "178.550884000026",

Continue reading

Caret Training Issues in R

Issue I started playing with caret package recently and I’m trying to understand the training arguments. Below I used the Sonar dataset and created three imputs and the output. library(caret) library(mlbench) data(Sonar) set.seed(107) SonarImput1<-Sonar[,1:60] SonarImput2<-Sonar[,1:2] SonarImput3<-Sonar[,1] SonarOutCome<-Sonar[,61] mlp <- caret::train(SonarImput1,SonarOutCome,

Continue reading

syntax highlighting while rendering SQL using knitr

Issue knitr will execute SQL code using engine=’mysql’ but not highlight syntax: \documentclass{article} \begin{document} <<engine=’mysql’, engine.opts=”-h localhost”>>= SHOW DATABASES; @ \end{document} On the other hand using engine=’highlight’ will highlight the code but not execute it. \documentclass{article} \begin{document} <<engine=’highlight’, engine.opts=’-S sql

Continue reading

Sweave syntax highlighting in output – revisit

Issue My question is the same as the one in the link Sweave syntax highlighting in output. I have followed the suggestion by daroczig https://tex.stackexchange.com/questions/5113/how-to-colorize-syntax-using-r-sweave, and created the following test.Rnw file: \documentclass{article} \RequirePackage{fancyvrb} \RequirePackage{listings} \SweaveOpts{keep.source=TRUE} <<SweaveListingsPreparations, results=tex, echo=FALSE, strip.white=false>>= require(SweaveListingUtils)

Continue reading

Error in for loop in ELO rating algorithm

Issue I’m trying to run the ELO rating code from here https://github.com/xsankar/hairy-octo-hipster/blob/master/ELO-538.R The dataset I’m using is here https://www.mediafire.com/file/0a5v393ki775vw9/sport2.xlsx/file The code I’m running is slightly modificated, I’m working with only 17 weeks instead of 22 as in the original code,

Continue reading

Model fitting functions and environemnts

Issue Here is a kind of minimal example for a problem I stumbled upon: mylm <- function(formula,data,subset=NULL){ mysubset <- subset # some other clever manipulation lm(formula,data,mysubset) } mydata <- data.frame(x=rnorm(10),y=rnorm(10)) mylm(y~x,mydata) # this fails! The reason why the last line

Continue reading

Environments in R Shiny

Issue At http://shiny.rstudio.com/articles/scoping.html the rules for scoping in shiny are well explained. There are 3 environments or levels nested inside each other: objects available within a function, within a session and within all sessions. Using <- will change the object

Continue reading

R shiny object scoping

Issue I’m trying to access an object(a<-get(obj1,envir=parent.environment())) residing in the calling environment from the called environment myf and I can’t get it working. Error I’m getting is Object obj1 not found. I tried parent.frame()also. Any ideas? library(shiny) shinyApp( ui =

Continue reading