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

How can I avoid clipping my xticks?

I'm plotting some data that has an associated date. However, the far most right xtick (Apr 2017) is clipped because the xtick is too long. Besides rotating or reformatting the tick, how can I avoiid this sort of clipping? ...
more »

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

compare splines and polynomials

I'm trying to write a function to compare the basic model between splines and polynomial regression. But when I use model$formula option, that I have in my model, and use it into a gam function with the next variable, I receive an error: Error in...
more »

2017-03-19 17:03 (1) Answers

mutate a column conditionally in dplyr

with a df like below, using dplyr I need to mutate the fields val1, val2, val3 conditionally. > df <- data.frame( id = c(1,2), loc=c("loc1", "loc2"), val1=c(80,64), val2=c(240,32768), val3=c(32768, 64) ) > df id loc val1 val2 v...
more »

2017-03-19 16:03 (2) Answers

R recalculate data to weekly usage

I have the following problem to solve: I download the data from Google Analytics, consisting of three columns: column A the factor variable (user ID), column B, the date of the session, and column C number of sessions or other metrics. I want to cre...
more »

2017-03-19 15:03 (1) Answers

can't install data.table package in R

Thanks for clicking in. I've been trying to solve this for hours but nothing seem to work. My operating system: MacOS sierra OS version: 10.12.3 R version: 3.3.3 I've followed the data.table download instruction here:
more »

2017-03-19 15:03 (1) Answers

finding yesterday's date using R

In one of my R scripts I need to find the date of yesterday, I can do that easily on my mac with this command. yesterday <- format(Sys.Date()-1,"%m/%d/%Y") yesterday [1] "03/17/2017" So essentially the Sys.Date()-1 gives me yesterday's date. Ho...
more »

2017-03-19 02:03 (1) Answers

How to deal with NSE and usemethod

Have a look to this "simple" functions : test <- function(x,...){ UseMethod("test",x) } test.default<-function(x,y,data){ message("default") print(deparse(substitute(x))) print(deparse(substitute(y))) print(deparse(substitute(data...
more »

2017-03-18 23:03 (3) Answers

Identify if in parallel call

I have a generic chunking function that breaks big calls into smaller pieces and runs them in parallel. chunk_it <- function(d, n, some_fun) { # run n chunks of d in parallel dat <- foreach(...) %doPar% { some_fun(...) } } I want t...
more »

2017-03-18 22:03 (2) Answers

Handling extra rows in colMeans calculations

I'm an occasional R-user working with several large annual datasets with one column for year and another for the location, similar to the following (which I'll call "timeseries"): Year L1 1960 1.11 1961 1.14 1962 0.75 1963 0...
more »

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

R Recover original data.frame from model.frame

In R, you can fit GAM models from the mgcv package using a formula which contains transformations such as log or sqrt and by default the model.frame is returned (only the variables specified in the formula with transformations applied). Is there any...
more »

2017-03-18 19:03 (3) Answers

R ggplot2: draw segment between points

How can I use geom_segment to draw lines on plot, after the data have been melted with reshape2? # Tiny dataset facet_group <- c("facet1", "facet1", "facet2", "facet2") time_group <- c("before", "after", "before", "after") variable1 <- c(1,...
more »

2017-03-18 17:03 (1) Answers