Time Series Interpolation

I have two series of data (calibration and sample) and am trying to interpolate the calibration data from monthly to the frequency of the sample which randomly changes between minutely to secondly. I tried this (Interpolating timeseries) and here's ...
more »

2017-03-21 21:03 (1) Answers

Get length of runs of missing values in vector

What's a clever (i.e., not a loop) way to get the length of each spell of missing values in a vector? My ideal output is a vector that is the same length, in which each missing value is replaced by the length of the spell of missing values of which i...
more »

2017-03-21 20:03 (3) Answers

Using R functions as a list

I am creating an R list comprising of few functions as : funs <- list( + sum = sum, + mean = mean, + median = median + ) In order to use lapply, the Hadley Wickham's book that i am referring to uses : lapply(funs, function(f) f...
more »

2017-03-21 13:03 (2) Answers

Add leading zero within a character string

One column of my data.frame looks like the following: c("BP_1_CSPP", "BP_2_GEGS", "BP_3_AEAG", "BP_4_KPAP", "BP_5_TAKP", "BP_6_GGDR", "BP_7_MQQP", "BP_8_EEEE", "BP_9_RSDP", "BP_10_APAS", "BP_11_KRGG", "BP_12_RSQQ", "BP_13_QQLS", "BP_14_EPEV", "BP_...
more »

2017-03-21 10:03 (1) Answers

how to match multiple patterns in string?

How do i match multiple patterns and fetch the value corresponding to that pattern. I have a table like this : library(data.table) set.seed(1) table_1 <- data.table(names = c('bluecdsd','red321','yellowVsds523','423_black','ewrwblack'), ...
more »

2017-03-21 06:03 (2) Answers

How to fit this function with ggplot?

I have this code, that produce the underlying plot: ggplot(data = df.wind, aes(x=variable, y=value)) + geom_boxplot(fill="gray70")+theme_gray()+ stat_summary(fun.y=mean, colour="darkred", geom="point", shape=18, size=3,show_guide = FALSE)...
more »

2017-03-20 16:03 (1) Answers

Adjust function to work with dplyr/magrittr

I have: df <- data_frame( a = 1:2, b = list(1:10, 4:40) ) and foo <- function(x) mean(unlist(x)) The following works as expected: df$b %>% foo However, I was not able to figure out which modifications of foo are needed in order...
more »

2017-03-20 15:03 (3) Answers

Convert data into time stamps in R

I have a data set with observations for a few month, where every day contains an observation for every hour (24 hours). There is a Date and a Time variable, and I would like to make a time stamp combining the two in order to predict the price as a ti...
more »

2017-03-20 10:03 (0) Answers

creating a variable names out of character vector

There are occasions where a vector with column names of data frame need to be passed into a function ( dplyr mutate in my case). example column name vector is a as c(V1, V2, V3, V4, V5, V6, V7, V8, V9, V10) I can construct this as a character vecto...
more »

2017-03-20 03:03 (1) Answers

Repeat data.frame, add a primary key

I've got a data frame. say, data.frame(x = c(1, 3), y = c(5, 0), id = c("A", "B")) And now I want to duplicate it so I have a duplicate in the same data.frame. I'd end up with something like this, data.frame(x = c(1, 3, 1, 3), y = c(5, 0, 5, 0...
more »

2017-03-20 01:03 (1) Answers