Calculate Realized Volatility in R
I am attempting to calculate the realized volatility of the members of the S&P 500 over a specific interval. I am having trouble looping through the index and storing the values.The process should...
View ArticleCommon breaks and free axes for overlapping lattice histograms
What is the required incantation to achieve an overlapping, faceted lattice::histogram with common break points (across groups, but potentially varying across panels)?For example, assume I want the...
View ArticleHow to divide specific column with rest of columns
I have matrix like this (first column names rest are values, separator i tab):name1 A1 B1 C1 D1 name2 A2 B2 C2 D2 Matrix could be huge (it is mean about hundreds rows and columns). It is allays same...
View ArticleError: Missing $ inserted when using kable
I am attempting to output a latex table using r markdown, kable, and kableExtra. I needed to use conditional logic to add colors to my table with cell_spec. But with the pdf output, it shows latex code...
View ArticleR: ggplot2 density plot shows wrong fill colors
I would like to plot densities of two variables ("red_variable", "green_variable") from two independent dataframes on one density plot, using red and green color for the two variables.This is my...
View ArticleHow can I make the bars in this ggplot appear with gganimate?
I am newbie with R but have some time on my hands and am trying some stuff out. What I like most is animating graphs/plots so that's what I am trying to do. I want to create a plot where you can...
View ArticleEfficiently preserving array dimensions in R
The below R code fills an array of specified dimensions with positive integers generated randomly via a probability vector. subset.haps <- NULL haps <- 1:4 num.specs <- 100 probs <-...
View ArticleWhat is the difference between the various R robust regression functions -...
I am rather new to R and am interested in applying a robust regression technique (due to its ability to better handle outliers and influential data points) to a simple dataset to find good linear and...
View ArticleR how get a date from variable in character
I have data that has dates in a character format, as "JAN2005","FEB2005","MAR2005", such as : Test <- data.table(c("JAN2005","FEB2005","MAR2005","APR2005"),c(436.6,543.1,417.3,687.4)) Is there a...
View Articlehow to sample from an upside down bell curve
I can generate numbers with uniform distribution by using the code below:runif(1,min=10,max=20) How can I sample randomly generated numbers that fall more frequently closer to the minimum and maxium...
View ArticleHow to build a function in R that splits variables into intervals and...
I try to split a Age variable into intervals, calculate mean, sd and a count for the intervals then save the outputs for every interval in a vector and then combine these vectors to a data frame where...
View Articleggforest function returns error message when used with coxph
when applying ggforest() to a coxph object I get the follwoing error messageerror in ggforest(res.cox3, data = Selection_cox) : class(model) == "coxph" are not all TRUE res.cox3is the output of coxph()...
View ArticleHow can I get weighted quantiles from a sparsely populated data frame?
I'm looking for some help with adding some columns to a data frame that I can't seem to get right. My df is about 40,000 rows x 30 columns and is structured like this:Key 0 1 2 3 4 5 6 7 8 9 10 11 12...
View ArticleHow to keep style format unchanged after writing data using openxlsx in R
I am using openxlsx in order to write the outputs of my data. I have used the following code to read my data using readxl. df1=read_excel("C:/my_data.xlsx",skip=2);Now I want to write the output and...
View ArticlePredictors are in random order in sjPlot using tab_model (r) (with...
I'm using the tab_model function in sjPlot in r. This function normally works smoothly for me, however, I noticed that the output table is oddly ordering variables in an order other than is in the lmer...
View ArticleHow to parallelize gsub currently in a for loop in R?
I'm fairly new to trying to run parallel processes in R because most of the data I work with just isn't that large. However, I am no working with a larger set of data where I am attempting to 'find and...
View ArticleIterate over data frame by elements of a list
I am trying to merge two data frames based on a subset on common IDs. Let me demonstrate:library(tidyverse) set.seed(42) df = list(id = c(1,2,3,4,1,2,2,2,1,1), group =...
View ArticleChi-Square test for groups of unequal size
I'd like to apply chi-square test scipy.stats.chisquare. And the total number of observations is different in my groups.import pandas as pd...
View ArticleError with constrained curve fitting through specific points using the cobs...
I'm trying to find the best fitting curve through a given set of points. The fitted curve must also pass through these points. I found an answer on Cross Validated which suggested to use the cobs:...
View ArticleRLE function from scratch in R? [closed]
Can anyone help me write a function similar to the source code of rle from scratch using loops in R? I want to test the performance of using loops vs apply.
View Article