weekend dates within an interval R

I'm trying to identify whether or not a weekend fell within an interval of dates. I've been able to identify if a specific date is a weekend, but not when trying to look at a range of dates. Is this possible? If so, please advise. TIA. library(lubri...
more »

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

Customize R base plot fonts (macOS)

I have followed this blog to customize base R plot font on macOS (using quartzFonts() in .Rprofile), with success to a certain degree. My problem with this approach is, defining a new font family has to be put in a function such as .define.fonts() an...
more »

2017-01-11 19:01 (0) Answers

POSIX date from dates in weekly time format

I have dates encoded in a weekly time format (European convention >> 01 through 52/53, e.g. "2016-48") and would like to standardize them to a POSIX date: require(magrittr) (x <- as.POSIXct("2016-12-01") %>% format("%Y-%V")) # [1] "2016-48" as...
more »

2017-01-11 18:01 (0) Answers

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

Split a string with varying length in a data table

I want to create a column based on part of a string within another column. The reference column follows the general format of: GB / Ling 31st Dec I want to extract the word "Ling" in this case and is of varying lengths. My approach so far has been...
more »

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

R Shiny Progress Box

I am working on a shiny app and have implemented my progress bar and modified it how it wanted using .progress, .progess-bar and .progress-text within my CSS. I have it nearly how I want, but I just need to get rid of the grey popup box with the x (s...
more »

2017-01-11 00:01 (1) 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

is it possible to run R as a daemon

I have a script in R that is frequently called during the day (by other scripts). I call R in a terminal using Rscript code.R I notice it takes a lot of time to load packages and set up R. Is it possible to run R as a background service which I ...
more »

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

How to maintain size of ggplot with large legends

I have a plot that is a simple barplot of number of each type of an event. I need the legend of the plot to be under the plot as some of the events have very long names and were squashing the plot sideways. I tried to move the legend underneath the p...
more »

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

R: How to split string and keep part of it?

I have a lot of strings like shown below. > x=c("cat_1_2_3", "dog_2_6_3", "cow_2_8_6") > x [1] "cat_1_2_3" "dog_2_6_3" "cow_2_8_6" I would like to seperate the string, while still holding the first part of it, as demonstrated below. "cat_...
more »

2017-01-10 11:01 (2) 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

stringdist on one vector

I'm trying to use stringdist to identify all strings with a max distance of 1 in the same vector, and then publish the match. Here is a sample of the data: Starting data frame: a = c("tom", "tomm", "alex", "alexi", "chris", "jen", "jenn", "michell...
more »

2017-01-10 03:01 (3) Answers

summing across rows, leaving NAs in R

In R, I would like to sum across rows but keep NA's as NA if the whole row is NA. My data contains 0's and I want to count them as such. E.g.: colA colB colC Total 1 NA 2 3 NA NA NA NA 0 NA NA 0 3 0 NA ...
more »

2017-01-09 21:01 (5) Answers

Prevent number formatting when using tidy

I'm using tidy to format the Chunks of my rMarkdown file. How can I prevent that numbers, especially long numberes, are formatted by tidy? For example: set.seed(3585) n=10000 loginkomens_prog1 = c(rep(10,0.3*n), rnorm(0.7*n, mean=11, sd=1)) inkome...
more »

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

Adding extra text to axis labels in ggplot

I want to create nice confidence interval plot for my data frame df: > df Estimate Lower Upper A1 0.005414976 -0.01227699 0.02310694 A2 0.004046546 -0.01368911 0.02178220 A3 0.002761602 -0.01491484 0.02043804 A4 -0.002860038...
more »

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