Stay up to date
We'll highlight new content in your collectives with a blue activity indicator on navigation items and posts.
Manage preferences
Questions
Browse questions with relevant R Language tags
516,273 questions
0
votes
0
answers
18
views
Making data.frames of different lengths the same length based on same values in one column across data.frames (or: how to manage subsetting)
I am working with 14 data.frames, each is a year's worth of crime data from NIBRS. The files are titled NIBRS2010, NIBRS2011 . . . NIBRS2023. Each of them has a different number of observations, but ...
0
votes
1
answer
15
views
Increase margins of common legend from ggpubr
I am trying to increase the size of the margins of a common legend built when using ggarrange. I could increase the width of the plot, but I do not really want to do that. What do you suggest?
...
2
votes
1
answer
53
views
Get matrix of branch actual length to species tips
Based on this example I have a phylogenetic with species at the tip and branch lengths (that are not necessarily 1). My goal is to calculate phylogenetic diversity multiplying a species community ...
0
votes
0
answers
43
views
How many output features per layer in a neural network? [closed]
I am training a neural network using R-Torch for a regression problem. My dataset has 22 features, and I currently have a neural network composed of one hidden layer and one output layer.
My question ...
3
votes
1
answer
52
views
How to format numbers with commas using table1
How can I format table1 columns with comma format? The sample data below has fewer rows and it does not display big values that require commas because I can't post my huge dataset. I wonder if someone ...
-1
votes
0
answers
27
views
Is there a way to model fraccional panel data in R? [closed]
I have a panel data with T = 20 and a response variable which is a percentage. I know I can't use standard linear panel model because of the nature of my response variable. I could use beta regression,...
1
vote
0
answers
31
views
Unrecognized data type in write_xlsx [closed]
When exporting a dataframe to Excel, I keep getting warning messages for "unrecognized data type. The dataframe comes from a matrix of variables that were created by processes earlier in the code....
1
vote
0
answers
32
views
Control the size of the output plot in R notebook in Positron
I want to control the size of the output plot in Positron in R ipynb notebooks.
In RStudio in markdown, I would start the chunk with {r fig.width=9,fig.height=5} and I could resize the plot to fit my ...
1
vote
1
answer
67
views
How to correctly read German special characters from CSV file in R on Linux?
I am trying to load a German CSV file into R on Fedora Linux 42, but the region names containing special characters (like u-umlaut, o-umlaut, eszett) are not rendered correctly.
Here's a simplified ...
-1
votes
0
answers
46
views
Does this pivot_wider R command need to be changed due to an update? [closed]
I've been using the following code for about a year to expand data columns containing multiple variables:
wh_wide_color <- wh_data %>%
separate_rows(warp_color,sep=";")%>%
...
2
votes
2
answers
59
views
Non standard evaluation in formula argument
Problem
I would like to fit multiple logistic regression models in R for different values of i:
glm(mpg_20 ~ poly(horsepower, i), data = Auto)
My problem is that the call argument of the resulting ...
0
votes
1
answer
35
views
Backslashes interfering with json processing [duplicate]
I'm having trouble processing a file in R. I've seen that backslashes are difficult to deal with in R, but that question is old and I'm hoping that someone has something that will help. Here's an ...
2
votes
2
answers
61
views
Optimal data structure for time-series analysis
My data is large CPI dataset containing headline CPI as well as various subindexes (i.e. food, non-food, services). Initial data stored in Excel spreadsheet in wide format like this:
name
2002Q1
...
1
vote
0
answers
27
views
How to fit constrained three-part linear spline models to time series data? [closed]
I'm working with time series data representing nighttime lights (NTL), and I'm trying to model the response of different areas to a known disruption, where the disruption has a known start and end ...
14
votes
1
answer
211
views
Is there an equivalent of dplyr data pronouns in data.table?
Is there a way to tell data.table to look for an external variable instead of a column name, just like what you can do with the .env pronoun in dplyr?
Imagine you have a dataframe with the column name ...
2
votes
1
answer
20
views
sv_dependence plot with shapviz and same feature for x axis and colour
I am sorry to ask this question again (first attempt here: shapvix sv_dependence color_var based on same feature), but it was closed because not enough details were provided. Below is an updated ...
2
votes
0
answers
34
views
R expressions for branch labels in `rpart` object
Given an rpart object representing a classification tree, I want to represent each split in the tree as an expression in R syntax.
This is almost possible using the labels generated by plotting or ...
2
votes
1
answer
85
views
Filter grouped data with conditional statement in R
The data frame below is grouped by id:
id<- c(1,1,1,2,3,3,4,4,4,5,5,6)
x <- c(0,1,0,0,1,1,0,0,1,0,0,1)
df <- data.frame(id, x)
I am looking for a way to filter the data in R based a ...
1
vote
2
answers
85
views
Persist R function defined in Rprofile even if user clears environment
I have an rprofile that is used for multiple users spinning up sessions in a shared jupyterhub. In it I define a function that sets some parameters for closing out idle sessions (basically it ...
1
vote
1
answer
38
views
Summary of cumulative incidence for multiple variables using tidycuminc
I want to generate a summary table of cumulative incidence estimates for several variables at once in a competing risks scenario using the tidycmprk package. It is possible to produce such a table for ...
0
votes
1
answer
49
views
Create Summary Table and make separate columns for categorical values [closed]
I want to make a descriptive table that summarize the different numeric columns in the dataset, for example if I have a column for Age, it summarize the value in Age column like this template: the ...
0
votes
1
answer
79
views
How to load a .txt file into R
I am trying to import a .txt file into R. It is a NIBRS data file for 2014 if anyone has specific experience with that.
I have tried read.table, read_file, and read_tsv (from Importing a .txt file ...
2
votes
1
answer
42
views
Using tidycmprsk and ggsurvfit to make a ggcuminc plot, I can't add a p value with add_pvalue()
I'm running into an error when trying to add a p value to a cumulative incidence function plot using tidycmprsk and ggsurvfit, and I can't get around this error:
`add_pvalue()` works with objects ...
1
vote
0
answers
31
views
Run reticulate::py_require() once on package installation
We have an internal python library that we want to build an R wrapper for. The python package only needs to be installed once and not every time. The documentation says to use py_require() over ...
2
votes
1
answer
41
views
Combining matrices (above and below diagonal)
Say I have this matrices:
emp <- matrix(nrow = 13, ncol = 13)
emp2 <- matrix(nrow = 13, ncol = 13)
emp[lower.tri(emp)] <- 2
emp2[lower.tri(emp)] <- 3
And I want to combine them so below ...
1
vote
0
answers
29
views
shinybusy does not work in bslib::page_navbar
I would like to use the shinybusy package to display a custom GIF as busy indicator at start up. While it works well in a fluidPage, using bslib::page_navbar throws an error :
Here the code I used, ...
0
votes
0
answers
58
views
Why is it possible to access a named list element by a shortened name in R? [duplicate]
I've just discovered that in R, using $ you can access an element of a named list using a shortened name (anything between the full name and the first letter only works). It works as long as the ...
1
vote
2
answers
53
views
Creating (ggplot2-)boxplots based on integer x values with correct spacing on the x axis
I am trying to visualize my benchmarking results where for three values of the discrete hyperparameter p and two values of categorical hyperparameter q, I have 50 runtimes. I am trying to create a ...
2
votes
1
answer
80
views
Prevent dropdown list closing when clicking on group headers
I have this JS script to make the pickerInput in my shiny app select all individuals by their respective groups, however the dropdown list closes every-time I select a group. I have tried to add evt....
2
votes
1
answer
46
views
How to bootstrap confidence intervals for predicted probabilities of a glm? [closed]
I am following the Maturity Schedules fishR Vignette by Dr Derek Ogle (https://derekogle.com/fishR/examples/oldFishRVignettes/Maturity.pdf) to generate stock assessments.
Following the code and ...
-1
votes
1
answer
45
views
how to get ggploty chart into asp.net c# web application [closed]
I have developed an asp.net, c# web application. To display charts in the web application, I generate them using R language's ggplot2 library, next save them as .png file, and then display them in the ...
1
vote
0
answers
69
views
Is there a way to offset the phase of the pattern in geom_abline()?
I have 2 parallel, sometimes overlapping lines of different colors that I create with geom_abline(). Here's a basic example:
ggplot(data.frame(x=1:5,y=1:5)) +
geom_point(aes(x=x,y=y)) +
geom_abline(...
4
votes
0
answers
44
views
Using @inheritParams for arguments from another package gets CRAN warning about missing package anchors
I have a package that has existed quietly and happily on CRAN for some years but in the last few months have received this NOTE accompanied by email warnings that the package will be withdrawn if I ...
4
votes
1
answer
59
views
R tidyxl determine exact color
I am loading an Excel file with shaded colors using the tidyxl R package, but I cannot figure out how to convert the octal decimal color to an rgb color.
Here is a basic example of my Excel ...
2
votes
0
answers
33
views
RODBC for MacOS M4 Sequoia with Windows Authentication to MS SQL Server
I recently got a Macbook Pro with M4 processor and Sequoia OS. I have been using Windows machine for a while and now trying to figure out my settings.
In my PC, I was able to use Windows ODBC ...
3
votes
1
answer
45
views
Predict function in Clogit (Conditional logit)
I am trying to understand how the predict function works for conditional logit. I tried to calculate it manually but it does not work. Any help would be greatly appreciated.
library(survival)
set....
0
votes
1
answer
47
views
How to combine ggplot2 and density plots using patchwork with aligned axes and proportional sizing?
I'm visualizing ecological niche shifts by combining a scatter plot (scaled environmental values) with marginal density plots of the respective variables — similar to a marginal histogram layout. I am ...
-2
votes
1
answer
74
views
The recycling rule: proceeding from experience [closed]
The "Introduction to R" chapter 5.4.1 states:
The precise rule affecting element by element mixed calculations with vectors and arrays is somewhat quirky and hard to find in the references. ...
0
votes
0
answers
46
views
Group by month the precipitation values and get index of maximum values for each month across all years [duplicate]
I have a dataset that looks like the one below (the real one is much bigger):
# A tibble: 120 × 3
month Pd_max Pmn_sum
<date> <dbl> <dbl>
1 2011-01-01 23 97....
2
votes
0
answers
49
views
Trying to add a graphs series to high carter in R
I am trying to add a MACD graph section to the highcharter graph similar to volume section.
I have the code for creating same.
Not sure as how they will be added as seperate section similar to volume.
...
1
vote
0
answers
19
views
How to write a group attribute using ncdf4?
It appears from the ncdf4 documentation (and my trials) that in R, I can define a global attribute by:
ncatt_put(mync,0,'att_name','attribute_text')
I can define a variable attribute in a group by:
...
-3
votes
0
answers
54
views
Merging df’s of different lengths to include duplicates [closed]
I am trying to merge two data frames. The first df is a large survey file with a deprecated structure. As such, the survey comes with a secondary file which includes an important metric called ...
1
vote
1
answer
84
views
How to print headers on every page when printing a long table using gt
Trying to print a long table that span multiple pages using gt, however, the tab_options(latex.use_longtable = TRUE, page.header.use_tbl_headings = TRUE) function in gt is being ignored and it does ...
1
vote
0
answers
24
views
ExportFiles() from REDCapAPI not finding files
I'm working on transferring a legacy project with many file attachments to a new REDCap build and using the exportFiles() function to export the files. I’m running into an issue where I receive the ...
1
vote
0
answers
42
views
how to use a shiny app to edit onedrive files?
I currently have a shiny app at "mycompany.shinyapps.io/myapp" that has access to read/change/create files inside a folder on google drive. All I needed to do is create a service account for ...
1
vote
0
answers
66
views
R with Reticulate crashes on MacMini and not on Windows
I want to use the Python versions of TabPFN and AutoGluon via the reticulate package in R. When I run the code on my laptop (Windows), everything works fine. However, as soon as I run the same code on ...
3
votes
1
answer
71
views
"Learning" R for Python translation
I'm a total beginner in "R". I'm doing a science research work, and I need to translate a R code (package) into Python (or C++, or whatever). I need help to understand what the matrix ...
1
vote
0
answers
41
views
Correlation matrix between 2 bulk RNAseq data [closed]
I have question in regards of correlating 2 bulk RNAseq gene expression matrix.
As you can see below, I have gotten the correlation heatmap between 2 matrix, although it looks a bit messy. Now I want ...
1
vote
1
answer
48
views
have a different color scale for violin plot and boxplot of the same data
I am trying to make a violinplot superimposed by a boxplot of the same (grouped data). I create a dummy variable to do this as follows:
x <- matrix(runif(n=1000,0,1),ncol =4 )
df <- reshape2::...
4
votes
1
answer
70
views
is there a way to plot multiple cuminc objects on the same plot?
I have a couple cuminc objects from the cmprsk package, which I want to appear on the same plot. However, plot.cuminc apparently does not work with lines. I tried to plot the objects together like so.
...
Members can contribute articles
Simply submit a proposal, get it approved, and publish it.
See how the process works
Simply submit a proposal, get it approved, and publish it.
See how the process works