Blog Archives

Changing function scope in GNU R example

July 26, 2012
By

In my last post I have discussed how to work around GNU R scoping rules using environment function. This time let us look at a practical example using recode function from car package.First let us look at how&nbs...

Read more »

Emulating dynamic scoping in GNU R

July 21, 2012
By

By design GNU R uses lexical scoping. Fortunately it allows for at least two ways to simulate dynamic scoping.Let us start with the example code and next analyze it:x <- "global"f1 <- function() cat("f1:", x, "\n")f2 <- function() cat("f2:", e...

Read more »

Solving mastermind with R

June 29, 2012
By

In my last post I have shown a solution to classical sorting problem in R. So I thought that this time it would be nice to generate a strategy for playing Mastermind using R.It was shown by D.E. Knuth that Mastermind code can be bro...

Read more »

Optimal sorting using rpart

June 24, 2012
By
Optimal sorting using rpart

Some time ago I read a nice post Solving easy problems the hard way where linear regression is used to solve an interesting puzzle. Following the idea I used rpart to find optimal decision tree sorting five elements.It is well known that...

Read more »

You should not use split in production code

June 7, 2012
By

Recently I have stumbled on a problem with split function applied on list of factors. The issue is that it might produce wrong splits when splitting factors contain dots.Here is the example of the problem. Invoking the following code:df <-...

Read more »

Visualizing car brand choices in ggplot2

June 2, 2012
By
Visualizing car brand choices in ggplot2

I always like to read new posts at chartsnthings as they always inspire me with new ideas for data visualization. Yesterday I have read an article on choices of car brands by members of parliament in Poland in Gazeta.pl. It contains a simple ...

Read more »

Cross-valitation variability example, part I

May 26, 2012
By
Cross-valitation variability example, part I

Recently I had a discussion with a student about variability of results obtained from cross-validation procedure. While the subject is well known there are not many examples on the web showing it, so I have written its simple presentation.Results from ...

Read more »

Emulating local static variables in R

May 17, 2012
By
Emulating local static variables in R

Recently I was writing a code allowing to plot multiple ggplot2 plots on one page. I wanted to replicate standard behavior of  plot  function that plots graphs in sequence according to  mfrow/ mfcol option in par...

Read more »

Porting cdplot to ggplot2

May 11, 2012
By
Porting cdplot to ggplot2

Last week I published a post on plotting tables in ggplot2. So the next natural step is to port cdplot to allow simple visualization of categorical variables against a numerical predictor.First part of the story covers binary variables. In th...

Read more »

Visualizing tables in ggplot2

May 5, 2012
By
Visualizing tables in ggplot2

Recently I wanted to recreate  assocplot  using  ggplot2. In the end I propose a simple way to visualize data arranged two-way tables using geom_tile.I used Titanic data set as an example combining age and sex dimensi...

Read more »