calculating time difference in R

You must turn your strings into date objects before you can do date/time arithmetic. Try this: a) Reading your data: R> dat <- read.table(textConnection(“start.date start.time end.date end.time 2012-07-13 15:01:32 2012-07-13 15:02:42 2012-07-05 18:26:31 2012-07-05 18:27:19 2012-07-14 20:23:21 2012-07-14 20:24:11”), header=TRUE) b) Working on one observation: R> strptime( paste(dat[,1], dat[,2]), “%Y-%m-%d %H:%M:%S”) [1] “2012-07-13 15:01:32” “2012-07-05 … Read more

Histogram with Logarithmic Scale and custom breaks

A histogram is a poor-man’s density estimate. Note that in your call to hist() using default arguments, you get frequencies not probabilities — add ,prob=TRUE to the call if you want probabilities. As for the log axis problem, don’t use ‘x’ if you do not want the x-axis transformed: plot(mydata_hist$count, log=”y”, type=”h”, lwd=10, lend=2) gets … Read more

ggplot plots in scripts do not display in Rstudio

The solution is to explicitly call print() on ggplot object: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) p <- p + geom_point() print(p) ggplot function returns object of class ggplot; ggplot2 works by overloading print function to behave differently on objects of class ggplot – instead of printing them to STDOUT, it creates chart. Everything is … Read more