How to write trycatch in R

I want to write trycatch code to deal with error in downloading from the web. url <- c( “http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html”, “http://en.wikipedia.org/wiki/Xz”) y <- mapply(readLines, con=url) These two statements run successfully. Below, I create a non-exist web address: url <- c(“xxxxx”, “http://en.wikipedia.org/wiki/Xz”) url[1] does not exist. How does one write a trycatch loop (function) so that: When … Read more

How to find the statistical mode?

In R, mean() and median() are standard functions which do what you’d expect. mode() tells you the internal storage mode of the object, not the value that occurs the most in its argument. But is there is a standard library function that implements the statistical mode for a vector (or list)? 35 Answers 35

Create an empty data.frame

I’m trying to initialize a data.frame without any rows. Basically, I want to specify the data types for each column and name them, but not have any rows created as a result. The best I’ve been able to do so far is something like: df <- data.frame(Date=as.Date(“01/01/2000″, format=”%m/%d/%Y”), File=””, User=””, stringsAsFactors=FALSE) df <- df[-1,] Which … Read more