Questions tagged [r]
R is a free, open-source programming language & software environment for statistical computing, bioinformatics, visualization & general computing. Please use minimal reproducible examples others can run using copy & paste. Show desired output entirely. Use dput() for data & specify all non-base packages with library(). Don't embed pictures for data or code, use indented code blocks instead. For statistics questions, use https://stats.stackexchange.com.
508,311
questions
0
votes
0
answers
8
views
Displaying Bar Graph in Shiny Dashboard Based on Select Input
I’m working on an interactive Shiny dashboard in R and I’m encountering an issue with my bar graph when no specific input is selected.
Here’s what I’m trying to achieve:
I have a bar graph that ...
0
votes
1
answer
17
views
Plot datetime data as just month not month-year
I have a data frame that looks like this:
structure(list(date = structure(c(1592611200, 1624665600, 1626480000,
1620086400, 1624147200, 1624752000, 1626566400, 1.566e+09, 1621036800,
1651536000), ...
0
votes
0
answers
16
views
Regression with a 0-1 variable. Should be the same as running a t-test, but I get a different p-value [migrated]
I have a dataset in R where I have volatility estimates (in my case, just standard deviation of minute returns on that day) for different days:
Date, Volatility, DayType
The variable DayType is 0 or ...
0
votes
0
answers
12
views
R: stat_density2d change color of density surface?
I'm using this example to create a heatmap in R:
https://www.sharpsightlabs.com/blog/how-to-create-a-crime-heatmap-in-r/
ggmap(map_sf) +
stat_density2d(data = sf_crime, aes(x = lon, y = lat, fill = ....
0
votes
0
answers
16
views
How do I get rid of the weird long floating point error numbers that are shown when I convert a vector to a name of a vector [duplicate]
This function shows the floating point error when displaying the vector as names of another vector but not when it is displayed "normally"
test <- rep(NA, times = length(seq(from = -0.5, ...
0
votes
2
answers
28
views
Find average temperature from a range of datetime for each day in dataframe
This is a subset of the dataframe I have:
structure(list(name = c("waldorf", "waldorf", "waldorf", "waldorf",
"waldorf", "waldorf", "...
-1
votes
1
answer
18
views
Possible issues with text encoding
I'm having a strange problem when I read a .csv file using read_csv. I'm afraid I don't think I can produce a reproducible example because the issue may involve my current R/RStudio session and how ...
0
votes
0
answers
11
views
Google Cloud Platform Maps API key: Best practice to use in R to avoid incurring large API costs?
I'm using google maps API and ggmap to create a simple map of NYC in an RMarkdown document, in R:
install.packages("ggmap")
ggmap::register_google(key = "<your-api-key>", ...
0
votes
0
answers
13
views
Why does my mutate(across()) function not work in lapply? [duplicate]
I have a simple function that works just fine on one data frame but doesn't do anything when I use it in lapply.
For example:
df1 <- data.frame(x = c(1:5), y = c(11:14, NA))
df2 <- data.frame(...
-4
votes
0
answers
25
views
Dplyr ( count for total number/treatment) [closed]
I have data frame with two columns the first column is the number of children under the age of five that receive a treatment and the second column classifies the type of the treatment. I would like to ...
0
votes
0
answers
27
views
How to extract from multiple zip files only the csv files whose name starts with a specific string of characters in r? [duplicate]
Let's consider a folder myfile containing more than a hundred zip files (z001.zip, z002.zip, z003.zip ...) each always including 4 distinct csv files whose names always start with these three letters ...
0
votes
0
answers
15
views
Increasing fontsize of numbers in forestplot in R
I am trying to prepare a forest plot for summarizing patient survival outcomes in multiple cohorts using the forestplot package in R. The plot comes out fine but I am struggling to increase the size ...
0
votes
0
answers
18
views
Problems running accuracy metrics on Validation_Set using fable package
I am unable to let the ACCURACY function point only to the Validation_set. The code perfectly works only in case the first argument of Accuracy is the whole dataset("data_tsibble") but in ...
-1
votes
1
answer
33
views
Produce table with data bars in base R or ggplot2
I am looking to make a table with horizontal bar graphs in each cell to display continuous numeric data with 2 categorical independent variables. It would look similar to the below (fictional data):
...
-1
votes
0
answers
21
views
Getting "invalid 'type' (character) of argument" error with numeric values when I do apply.weekly(data$x, sum) [closed]
I have a time series object and I am creating a list of the variables at different timesteps.
when I do apply.weekly( , mean) it works fine, but when I want to sum the values over a week it gives me..
...
1
vote
4
answers
63
views
Find row in Matrix A which is closest two Matrix B
Lets say I have two matrices A and B given by
set.seed(123)
m1 = matrix(runif(10*5), nrow = 10, ncol = 5)
m2 = matrix(runif(10*5), nrow = 10, ncol = 5)
I want to find for each row in matrix A the row ...
0
votes
0
answers
24
views
Making a ggplot2 Sankey plot in R less crowded
If I have a dataframe in R (called connections_df), that shows the connections between the two endpoints (endpoint1 and endpoint2) with the corresponding chromosome (CHR):
endpoint1 ...
-1
votes
0
answers
37
views
Making lines not overlap
I am creating a DGE plot for 2 samples. I want the lines in the resulting plot to NOT BE STACKED on top of each other, bot to be next to each other (so that both are visible).
## Load packages
if (! ...
1
vote
2
answers
33
views
R function 'transform' ignoring argument 'check.names=FALSE'
I'm having issues with the function transform in R and the argument check.names.
For example:
df <- data.frame('A' = sample(1:10), 'B' = sample(1:10), 'C(%)' = NA, check.names = FALSE)
> names(...
0
votes
0
answers
46
views
Conditional variable for COMPLETE DATA [duplicate]
Attached data :
id = c (2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
vm = c("12", "13", "14", "15", "16", "17", "18" "19", &...
1
vote
2
answers
29
views
Change the absolute value of elements in a dataframe without changing their sign (+ / -)
I have a dataframe of cumulative changes, which I am trying to convert into (multiplicative) factor values.
If all values were positive, I could simply add 1: e.g. a 25% increase would be 0.25, adding ...
1
vote
1
answer
14
views
Pattern fill in highcharter bar chart
I would like to create a column or bar chart with pattern fill in an R shiny app. It seems to me that highcharts and related highcharter package should be able to do the job, but I could not find a ...
3
votes
1
answer
48
views
In R, how and where does the underlying C functions get their argument inputs?
I'm trying to understand what happens at the C level when I call a function in R. For instance, print("Hello, World!") will call UseMethod("print"). From the "table" in ...
-1
votes
0
answers
19
views
In ggHoriPlot, geom_horizon will create fill Categories. What the meanning?
In ggHoriPlot,geom_horizon will create fill Categories ypos3 .. yneg1 ..yneg13 ,refer to the legend in attached image.
How to understand Categories and it's created according what kind of logic ? ...
0
votes
0
answers
5
views
KFAS package: Why I can't pass SSMCustom state space object to SSModel formula?
I am trying to create SSModel from KFAS package in R. In the code I got from someone it was done this way:
model <- KFAS::SSModel(ts ~ -1 + SSMcustom(Z = Z_t,T = T_t, R = R_t, Q = Q_t, a1 = a1_t, ...
2
votes
1
answer
72
views
lme4 (glmer): Something buggy with treatment of factors in 4-way interactions
I have a dataset for which I am making a series of complex generalized linear mixed-effects models with the lme4 package in R. I have experience with glmer and this type of experimental data, but I'...
0
votes
1
answer
21
views
how can I force the scale in ggplot to be in the middle of the data range?
In the plot below, the range in a goes from 0.001 to 0.7 but the legend doesn't have the middle value in the cyan color. Is there a way I can force that the middle value in the range of a be in the ...
0
votes
0
answers
11
views
How to change the line-height only in the code chunk when using Rmd in Rstudio
I'm looking for a way to modify the .rstheme file and adjust the line-height in a R markdown document. Specifically I want the code chunk in the Rmd file to have a line-height of 1.2 and for the other ...
3
votes
0
answers
25
views
R parallel: Stopping a cluster you don't have the object for?
I am working with a function that starts with parallel::makeCluster() and ends with parallel::stopCluster(). Sometimes it crashes in the middle and does not stop the cluster.
Demonstration code:
...
0
votes
0
answers
27
views
How to remove real-time NA rows?
I'm writing a code in shiny to input data in real time and download a csv file, but I want to remove rows with NA in the final output file.
Is it difficult to remove rows in real time in shiny?
Is it ...
0
votes
0
answers
11
views
RStudio: Failure to install 'imager'
I am attempting to do the tutortial "Getting started with imager", but the very first instruction library(imager) generates a long error message, with only the first part shown below
Error: ...
1
vote
1
answer
30
views
Fix order of stacks but allow colour to change
The data and code for this question were adapted from:
How to fill colors of stacked bar plot depending on colors column of df in R using ggplot
I want to fix the order of country appearance in each ...
-1
votes
0
answers
37
views
Exact same line of code not working between 2 PCs [closed]
On my home PC with R4.4.0
avg_demand_per_yearday <- aggregate(demand ~ yearday, df, 'mean')
it works as expexted. On my work machine with R4.4.1 an error occurs
Error in UseMethod("aggregate&...
1
vote
2
answers
53
views
Efficiently standardize a large matrix in R with foreach/doParallel?
I need to standardize (subtract the mean and divide by the standard deviation) the columns of several large matrices in R (roughly 300,000 rows by 10,000-20,000 columns).
The process has been very ...
0
votes
0
answers
21
views
Issues in my script to analyze a list of stock ticker symbols
The purpose of this script is to gather basic information about all S&P listed stocks from Wikipedia. It then uses the get symbol to extract price data over time, calculates log.return over that ...
0
votes
0
answers
13
views
Error in system(cmd, intern = intern, ignore.stdout = ignore.stdout, ignore.stderr = ignore.stderr)
I am running an R script that uses cifti and am getting this error:
Error in system(cmd, intern = intern, ignore.stdout = ignore.stdout, ignore.stderr = ignore.stderr) :
error in running command
...
0
votes
0
answers
54
views
aggregation based upon multiple criteria and time range (R)
Ultimately, I want to aggregate the amount column in my data over modular groups that do not yet exist but that are the composite of two existing groups and a time difference dimension.
I have a ...
0
votes
0
answers
10
views
Which versions to install to make RandomFields, RandomFieldsUtils, rpy2 compatible?
I am hoping to install some packages that people no longer update.
I need RandomFields (https://cran.r-project.org/src/contrib/Archive/RandomFields/), RandomFieldsUtils (https://cran.r-project.org/src/...
0
votes
2
answers
39
views
Why is this part of my code not adding the new columns to my data frame?
I have 13 datasets that are in .XPT format called data2010, data2011, data2012.. data2022. These are the BRFSS datasets from the CDC website. I have been trying to add three new columns to each of my ...
-1
votes
0
answers
28
views
Is there an R program that plot ROC curve nicely? [closed]
Is there any package that allows me to plot ROC curve like this? ?
The 0.95,0.9 are particular threshold values.
I tried the package verification with roc.plot(truth,v,xlab="FDR",ylab="...
1
vote
1
answer
63
views
How can I append duplicated groups of a dataset with changes to existing data in R efficiently?
I have data like this:
key_data <- data.frame(orig_letter=c("A","A","A","A","C","C","F","B","B","B&...
0
votes
0
answers
28
views
How to capture a legend event?
Is it possible to capture a legend activation / deactivation event of an echart using a shiny app?
mtcars |>
head() |>
tibble::rownames_to_column("model") |>
e_charts(model) |>...
1
vote
1
answer
16
views
leaflet() empty geometry Error Don't know how to get polygon data from object of class XY,GEOMETRYCOLLECTION,sfg
I was using the leaflet package in R, and I had this error (in the title) that took some time to track down. I could not find the exact error or solution posted, so I am posting.
I was using a ...
0
votes
1
answer
38
views
move inset plot legend
I have an inset plot with a legend that I want to be shown at the bottom of the overall figure. This legend isn't the same for the larger plot, since I added more layers to the inset plot. How can I ...
0
votes
0
answers
20
views
'Maximum call stack size exceeded' when using tsibble::fill_gaps() in a shinylive webr app
I am using shinylive (v0.2.0) to write a Shiny (v1.8.1.1) app to run in the browser (Safari v17.5, 19618.2.12.11.6) using webr. The app takes data where each row represents an event and counts the ...
1
vote
0
answers
35
views
Combine event binding and dynamic outputs in shiny
My Shiny app consists of selecting a set of parameters to generate outputs based on the corresponding data, where each parameter is dependent on the previous one to narrow down which data needs to be ...
0
votes
0
answers
43
views
Element does not exist in dataset when selected via selectInput
In the shiny app below I try to group by selected input but I get:
Caused by error in `all_of()`:
! Can't subset elements that don't exist.
✖ Element `abs_edu` doesn't exist.
This is my code:
library(...
0
votes
0
answers
41
views
Problem with dynamic linear model -> lagged variable explains 100% of my model [closed]
I created a regression model, which regresses a cycle component onto a lagged cycle component and various other variables.
It looks like this:
regoffice4 <- dynlm(
diff(diff(officecycle,1),1) ~ ...
0
votes
0
answers
46
views
Create a function that converts a dataframe into a format suitable for a treemap structure
I want to create a treemap for a dataframe using the Plotly package. For this purpose, I need to create a function that converts the dataframe into a format suitable for a treemap structure. On the ...
0
votes
1
answer
19
views
How to adjust x axis in coefficient plot with sjPlot's plot_model when x value range is smaller than -1,1?
I'm plotting multiple regression coefficients with plot_model and the x axis is automatically set to -1,1 even though the possible range of my values is smaller, which makes the estimates hard to see ...