And now for something a bit more esoteric….
I recently wrote a function to deal with a strange problem. Writing the function ended up being a fun challenge related to computing on the R language itself.
Here’s the problem: Write a function that takes any number of R objects as arguments and returns a list whose names are derived from the names of the R objects.
Perhaps an example provides a better description. Suppose the function is called ‘makeList’. Then
x <- 1
y <- 2
z <- "hello"
makeList(x, y, z)
returns
list(x = 1, y = 2, z = "hello")
It originally seemed straightforward to me, but it turned out to be very much not straightforward.
Note that a function like this is probably most useful during interactive sessions, as opposed to programming.
I challenge you to take a whirl at writing the function, you know, in all that spare time you have. I’ll provide my solution in a future post.
R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series,ecdf, trading) and more...

Zero Inflated Models and Generalized Linear Mixed Models with R.
Zuur, Saveliev, Ieno (2012).