Finding Time count between a time interval

I have a time variable say x. The class of my vector is a character x <- c("06:59:20","19:13:31", "06:08:02", "00:25:14", "19:25:01" ,"21:21:44" ,"19:04:25" , "19:43:31", "16:00:13", "05:15:37", "05:52:16", "21:47:51", "06:33:36"...
more »

2017-01-11 13:01 (1) Answers

The difference of na.rm and na.omit in R

I've just started with R and I've executed these statements: library(datasets) head(airquality) s <- split(airquality,airquality$Month) sapply(s, function(x) {colMeans(x[,c("Ozone", "Solar.R", "Wind")], na.rm = TRUE)}) lapply(s, function(x) {colM...
more »

2017-01-11 11:01 (2) Answers

Get a seq() in R with alternating steps

The seq function in R would give me a sequence from x to y with a constant step m: seq(x, y, m) E.g. seq(1,9,2) = c(1,3,5,7,9). What would be the most elegant way to get a sequence from x to y with alternating steps m1 and m2, such that something...
more »

2017-01-11 10:01 (4) Answers

How to add logo on ggplot2 footer

How to add image logo outside the plotting areas for ggplot2. Tried rasterGrob function from 'grid' package, but that keep's the image inside plot area. Here is the starter script: library(ggplot2) library(png) library(gridExtra) library(grid) gg...
more »

2017-01-10 18:01 (1) Answers

Vector version of do for/while loop

I'd like to be able to write a cleaner way of doing the following: I have a data.frame P (5000rows x 4cols) and would like to find the median values in columns 2,3 and 4 when the time-stamp in column 1 falls into a set range determined by a vector T...
more »

2017-01-10 09:01 (2) Answers

How to select unique columns in an R matrix

I want to select the unique columns in the matrix six on a simulation as follows: > set.seed(3) > sam = replicate(100, sample(1:3, 4, rep = T)) > (six = sam[,colSums(sam)==6]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] ...
more »

2017-01-09 04:01 (2) Answers

Word boundary regex issue

I'm having issues using word boundaries \b in my regular expression. I'm using R but the issue exists as well when I try The pattern I'm using is \bs\.l\.\b, and while I expected lines 1 and 3 below to match this pattern, only line...
more »

2017-01-08 21:01 (2) Answers

R: Aggregating History by ID and By Specified Data

I asked a similar question before and got great help: R: Aggregating History By ID By Date The difference was that for the former post I was interested in aggregating ALL historical information, but now I am hoping to specify only 90 days back. He...
more »

2017-01-08 20:01 (4) Answers