Hyperlinking text in a ggplot2 visualization

Currently if I want to show data in a table in R I can hyperlink text via markdown, html href, or LaTeX href. This is often nice for giving access to more info about a particular element w/o cluttering the table. How is it possible to give the sa...
more »

2017-02-15 21:02 (1) Answers

Time Series Subsetting by Integers

I've seen a lot of posts in regards to subsetting time series through specific date requirements, but I can not figure out how to subset based on integers. Consider: # create dummy data data <- ts(seq_len(96), start=c(2009,1), f=12) # create trai...
more »

2017-02-15 19:02 (2) Answers

Error in formula to neuralnet

This is actually a copy of a perfectly useful question whose answer was (partially) arrived at by the questioner. Original title: "Formulas with more than 512 characters for neuralnet model in R for text analysis". He eventually fixed the problem alt...
more »

2017-02-15 01:02 (2) Answers

Assign unique value for duplicated rows

I want to assign the value for each duplicated row by ID in R df <- data.frame(ID=c(1,1,1,2,2,2,2,2,3,3,4), Code = c("A","A","A","B","B","C","C","D","A","A","C")) > df ID Code 1 1 A 2 1 A 3 1 A 4 2 B 5 2 ...
more »

2017-02-14 23:02 (2) Answers

From string to regex to new string

I have a data frame that includes a column of messy strings. Each messy string includes the name of a single country somewhere in it. Here's a toy version: df <- data.frame(string = c("Russia is cool (2015) ", "I like ...
more »

2017-02-14 21:02 (3) Answers

parsing xml from a URL list

I have a list of URLs that direct to different xml files and I want to extract some info from them using R and the xml package. I am trying to do this with a for loop. I have this code but it gives me only the last xml (numtotal), how can I read al...
more »

2017-02-14 20:02 (1) Answers

Generate a sequence of time using R and lubridate

Is there an efficient way to generate a time-sequence vector with tidyverse and lubridate? I know the two can work with seq() when one use the number of dates as the interval. For example, with the input: seq(today(), today()+dyears(1), 60) one ca...
more »

2017-02-14 20:02 (0) Answers

Why does any() return NA when no true values

So we have this behaviour: any(c(TRUE, FALSE, NA)) #> [1] TRUE any(c(TRUE, NA)) #> [1] TRUE any(c(FALSE, NA)) #> [1] NA Anyone know the rationale for returning NA instead of FALSE? IMO the function should be testing for presence of non-FA...
more »

2017-02-14 13:02 (3) Answers

R t.test() with data.frames as arguments

There is a question on CrossValidated, where someone gave two dataframes instead of two vectors to the t.test function: http://stats.stackexchange.com/questions/261830/t-test-or-wilcox-in-r-and-how-to-apply-to-dataframe-splitted-in-2-groups/ See thi...
more »

2017-02-14 12:02 (2) Answers

ggplot2 - multiple plots scaling

I tried to generate multiple grid plots with ggplot2. So I would like to generate distribution plot with additional boxplot below x-axis and that for different groups and variables like that: CODE: I tried to do that with the following code : lib...
more »

2017-02-14 09:02 (1) Answers

Extracting non-object values from ecocrop in R

I'm working on crop-climate modelling using Robert Hijmans' package 'dismo' and more specifically the function 'ecocrop'. Ecocrop calls a series of 'hidden' functions including, .doEcocrop (ecocrop and .doEcocrop pasted below), which calculate the fi...
more »

2017-02-14 08:02 (0) Answers

R - Grouped Bar Plot Ordering Within Groups

Here is some R code and the graph it produces: library(ggplot2) year <- c("1950", "1950", "1960", "1960", "1970", "1970") weight <- c(15, 10, 20, 25, 18, 20) name <- c("obj1", "obj2", "obj3", "obj4", "obj5", "obj1") object.data <- data.f...
more »

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

Error in SVAR function of vars package

Using the vars package, I am trying to replicate a standard 4-variable SVAR model with quarterly data and 61 observations. Matrix A has a recursive structure and no restrictions were placed on matrix B (just identified model). The original model was ...
more »

2017-02-14 02:02 (0) Answers

Installing RSymphony using RStudio on macOS

I am trying to install the package RSymphony using RStudio in my MAC (to afterwards be able to install the package fPortfolio). After accepting with "Y" to install the package from the source, I get the message: > package 'Rsymphony' successfully...
more »

2017-02-14 00:02 (1) Answers

Calculate a Lagged column on itself

I'm certain there is an easier way to accomplish this. I have the following dataframe: B <- c(1, 1, 1, 0, 1, 2, 2, 0, 0, 0) A <- c(1:10) df <- as.data.frame(cbind(A,B)) What I would like to do is add a third column (C) that applies col...
more »

2017-02-14 00:02 (0) Answers