Skip to main content
The 2024 Developer Survey results are live! See the results

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.

0 votes
0 answers
2 views

Tools that is similar to Prython

I'm working on a biostatistics project using R. I have several datasets to work with. However, in the RStudio environment, I need to modify and execute each script one by one. Recently, I discovered ...
Ian Wang's user avatar
  • 157
0 votes
0 answers
11 views

Error using mcp2atm function for robust pairwise comparisons - undefined columns selected

I used a robust two-way ANOVA using the WRS2 package (R v.4.4.1), using the following code as suggested by Mair and Wilcox (2020) - the full dataset is on the bottom of this message: library(WRS2) ...
r.filogonio's user avatar
0 votes
0 answers
8 views

How to get predicted probabilities of being in each class of three using xgboost in R?

I am trying to train a xgboost model using iris dataset. The training code is shown below, and both prediction functions produce the same results. However, the length of the results is 135, while ...
Phoebe's user avatar
  • 109
0 votes
1 answer
15 views

Using R to generate lifespan plots

I have a dataset that records the lifespan and generation time of individual cell that I would like to plot as below: Example_RLS_plot Reference: https://doi.org/10.1186/s12951-022-01379-9 Here is my ...
Jie-Ning Yang's user avatar
-3 votes
1 answer
14 views

What it the R function to remove a couple of empty columns from a csv file

So I am working on this: a screen shot of a csv file and I am trying to delete the last 4 columns, what code should I use? I have it open on Rstudio and running R. I tried doing Df$column <- NULL ...
AdvEnTure21's user avatar
0 votes
0 answers
11 views

Predicted values in a Tweedie GLM-model

I need help with how to create an actual vs predicted plot for a Tweedie GLM model in R where weights are used. I have a Tweedie GLM model in R where I have derived the coefficients/factors for a risk ...
kabin's user avatar
  • 139
0 votes
2 answers
19 views

Export nested simple feature collection to geoJSON in R

I have used R to calculate a Voronoi tessellation I now want to use in an OSM umap. Because I want different areas to be easily distinguishable, following some hint at their github, I need a nested ...
mars412's user avatar
0 votes
0 answers
18 views

How to speed up R dist matrix for hierarchical clustering for large matrix input data?

I have a large matrix (approximately 35,000 x 35,000) and I'm preparing a distance object in R for hierarchical clustering. The base R function dist() is too slow, so I'm using the distances function ...
titi's user avatar
  • 609
0 votes
1 answer
15 views

Open with Python an R data.table saved as metadata in a Parquet file

With R, I created a Parquet file containing a data.table as main data, and another data.table as metadata. library(data.table) library(arrow) dt = data.table(x = c(1, 2, 3), y = c("a", "...
julien.leroux5's user avatar
0 votes
0 answers
6 views

I want to colorize the points of a Shapviz dependence output acording to the variable

I have been trying to change the colors of the points on each variable, but even though i've tried using scale_x_discrete, by and changing the colors, or using scale_color_manual(), nothing works for ...
Vicente Santana's user avatar
0 votes
0 answers
5 views

cLDA constraint for discrete-time models in R formulas

I work with longitudinal (repeated measures) models of clinical trial data. Patients are randomized to different treatment groups and measured over multiple pre-specified points in time. An example ...
landau's user avatar
  • 5,771
0 votes
0 answers
12 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 ...
Nandita Vaidyanathan's user avatar
1 vote
2 answers
26 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), ...
Ryan Gary's user avatar
  • 153
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 ...
Avocado's user avatar
  • 86
0 votes
0 answers
17 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 = ....
DiamondJoe12's user avatar
  • 1,691
0 votes
0 answers
19 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, ...
freyaisincompetent's user avatar
0 votes
2 answers
31 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", "...
Ryan Gary's user avatar
  • 153
-2 votes
1 answer
21 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 ...
whdaffer's user avatar
-1 votes
0 answers
16 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>", ...
DiamondJoe12's user avatar
  • 1,691
-1 votes
0 answers
16 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(...
Sara's user avatar
  • 45
-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 ...
Hamad Alonazi's user avatar
0 votes
0 answers
34 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 ...
denis's user avatar
  • 487
0 votes
0 answers
18 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 ...
accibio's user avatar
  • 535
0 votes
0 answers
21 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 ...
Mark_'s user avatar
  • 21
-1 votes
1 answer
36 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): ...
whv20's user avatar
  • 151
-1 votes
0 answers
22 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.. ...
Tatiana's user avatar
1 vote
4 answers
73 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 ...
MGP's user avatar
  • 2,511
0 votes
0 answers
25 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 ...
HKJ3's user avatar
  • 467
-1 votes
0 answers
38 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 (! ...
Marek Pospíšil's user avatar
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(...
SchlaWiener's user avatar
0 votes
0 answers
47 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", &...
user25334460's user avatar
1 vote
2 answers
30 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 ...
ravinglooper's user avatar
1 vote
1 answer
15 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 ...
kristofkelemen's user avatar
3 votes
1 answer
51 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 ...
cmd's user avatar
  • 51
-1 votes
0 answers
21 views

In ggHoriPlot, geom_horizon will create fill Categories. What the meanning? [closed]

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 ? ...
anderwyang's user avatar
  • 2,281
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, ...
Brzoskwinia's user avatar
2 votes
1 answer
81 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'...
Drew McLaughlin's user avatar
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 ...
L55's user avatar
  • 215
0 votes
0 answers
12 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 ...
m3m3m3's user avatar
  • 1
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: ...
bluemouse's user avatar
  • 452
0 votes
0 answers
28 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 ...
문경란's user avatar
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: ...
donman's user avatar
  • 57
1 vote
1 answer
33 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 ...
Alex's user avatar
  • 15.5k
-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&...
Siam Bhuiyan's user avatar
2 votes
2 answers
61 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 ...
bluemouse's user avatar
  • 452
0 votes
0 answers
22 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 ...
Tbiz Adeniyi's user avatar
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 ...
Edy's user avatar
  • 1
0 votes
0 answers
58 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 ...
Grum's user avatar
  • 25
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/...
Sasha Queequeg's user avatar
0 votes
2 answers
42 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 ...
Jalinne's user avatar

15 30 50 per page
1
2 3 4 5
7