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,266 questions
0
votes
0
answers
16
views
Download satellite data using http::GET but the files are incomplete
I'm trying to download lots of satellite data from a government website. When I download each file individually, by manually clicking the download button on the site, the files are about 13 MB each. ...
0
votes
1
answer
18
views
How to adjust Fable forecast .mean before autoplot?
I have been following the fpp3 textbook and using packages: fpp3, tidyverse.
I have a Fable forecast, but would like to make manual modifications to the .mean. This is easily done by accessing those ...
0
votes
0
answers
15
views
Pairwise T-test for Welch's F ANOVA
I need help with pairwise comparison following Welch's F test.
For your convenience, my minimal example is drawn from the example given in the R documentation.
df <- ToothGrowth
df$dose <- as....
1
vote
1
answer
41
views
how to use pivot functions in R with no proper column names
I have a fairly unconventional list of dataframes, each of which is essentially comprised of about six smaller data frames. Here is a toy example of one of the dataframes in the list:
structure(list(....
3
votes
1
answer
31
views
How to overlay a shapefile on leaflet minimap
Can anyone help me with this? I am trying to overlay a shapefile on the minimap using leaflet (addMiniMap). My code is below. The small sample shapefile can be downloaded from here: https://login....
1
vote
1
answer
45
views
Create a string from data in a dataframe column in R
I have a dataset which I am trying to validate. I created a column that contains the written rules for what to check for each row and would like to use paste0 to concatenate the data in that column ...
-2
votes
0
answers
37
views
How do I resolve object not found problems in R code [closed]
Hello I am trying to define my variables but R cannot find them. I want to do polynomial regression with more than one independent variable. First I wanted to define them as x1 and x2 but R cannot ...
-1
votes
0
answers
29
views
Query about DSEq2 package in R
I'm facing a problem to construct a DESeqDataSetFromMatrix data object. The code was
dds <- DESeqDataSetFromMatrix ( + countData = counts_data, + colData = col_data, + design = ~dex + )
# Error in ...
1
vote
1
answer
63
views
Why does `tapply` give a different result depending on the parameter of FUN
I am working on data analysis and came across the following.
Given a triplet data frame, consisting of indices i, j and value v, create a matrix m[i, j] = v.
A matrix element can have multiple values. ...
3
votes
1
answer
29
views
How to dynamically change the width of a bslib sidebar using an input?
I'm trying to implement a dynamic user controlled sidebar width into an app that uses a bslib page_navbar layout with multiple nav_panels. Each nav_panel has a layout_sidebar. I want the user to ...
4
votes
1
answer
57
views
How can I set "cr" as the default basis type in mgcv::gam instead of "tp"?
I'm using the mgcv package in R to build generalized additive models (GAMs), and I often use cubic regression splines (cr) instead of the default thin plate regression splines (tp) (mainly because cr ...
0
votes
0
answers
17
views
Repeated measures in RDA (aka "fixed" or "random" effects): why does Condition remove the contraints?
I'm running an RDA on a set of measures that have been taken in a landscape. For each landscape window, we've some parameters that describe the landscape there, and we've conducted, say, 10 measures ...
0
votes
0
answers
31
views
Customize flextable XML in Word documents using officer and flextable with new versions
I've extensively worked with older versions of the officer and flextable packages in R to create Word documents with tables. To achieve custom table formatting beyond the packages' default ...
1
vote
0
answers
46
views
Extracting polar coordinates from contour image in R for GAMMS
I am working with thousands of contour images that I will later use in a GAMMS analysis, so the output has to be structured as such. I'm struggling finding a way to do this, I DO know how to do data ...
2
votes
1
answer
60
views
How to find all near-matches between values in the same data frame column in R?
I have a data frame of phonetic transcriptions of words, and for each transcription, I need to find all the words with the same transcription but with "1.M", "1.N", and "1.NG&...
1
vote
0
answers
41
views
How can I address unevenly spaced temporal autocorrelation in mgcv gam's? [closed]
Data preview and problem at hand
Apologies in advance for a long post. I am a wildlife biologist trying to create a model for data collected from foraging seabirds. I have data from around 25 birds, ...
3
votes
2
answers
84
views
Count string values and collapse/aggregate
I have the following data:
aa <- data.frame(
group = c("asdf", "asdf", "asdf", "asdf", "asdf", "asdf", "asdf", "asdf&...
2
votes
4
answers
87
views
How to functionalize base R function like `with()`?
I am trying to write a function that operates similarly to with() where the function has a data argument, and two other arguments that I would like evaluated in the context of the data frame.
I ...
0
votes
1
answer
40
views
re-order factors on y axis of a gantt chart
I am trying to produce a Gantt chart with the locations on the y axis in alphabetical order but nothing I tried worked out. Here is the code:
gantt <- read_excel("2025-05-07_gantt_chart.xlsx&...
2
votes
0
answers
84
views
Results changed after updating R
I just finishing a manuscript and getting ready for publication. However, when I updated r from 4.4.2 to 4.5.0 today, I triple checked some results and got different numbers. I am running latent ...
0
votes
0
answers
37
views
Where are the x and y-axis when plotting with ggplot in rmarkdown? [duplicate]
I plot the following figure in rmarkdown with ggplot, however it appears without the x and y axis. Where is the issue?
I provide the full code with the chunk setup:
```{r, fig.retina=3}
Demand_total ...
3
votes
0
answers
50
views
Why does barplot() add space to x-axis margin even when par(mar=rep(0, 4))? [duplicate]
Base R plotting functions allow control of the plotting area through graphic parameters set with the par function. This allows for e.g. modifying or eliminating margins around the plot through the mar ...
2
votes
1
answer
44
views
How can I increase arrow and edge thickness in plot() with method = "graph" from arulesViz in R?
I'm using the arules and arulesViz packages in R to generate and visualize association rules. When I use plot() with method = "graph", the arrows and edges in the graph are extremely thin ...
1
vote
1
answer
39
views
How to write multiple named sheets to excel workbook using openxlsx
I need to use the openxlsx library due to java issues at my institution.
I have a list of dataframes called data_list that are simply named 1, 2, 3, etc.
> data_list
$`1`
Count TaxID ...
3
votes
1
answer
59
views
Space when plotting world map shapefile from 'rnaturalearth' package in R
In R, when plotting a shapefile from 'rnaturalearth', I get white space above and below the map. How can I produce the map without it?
world <- ne_countries(scale = "small", type="...
0
votes
1
answer
77
views
Create a two-way table in R base that displays concatenated game results between players
Objective
To create a function in R {base} that produces a square matrix showing concatenated game results between players. The matrix should display the result of each pairwise match, concatenating ...
0
votes
0
answers
43
views
R Package doesn't show dataset tooptip message
I'm developing a package that contains datasets, but I can't see the tooltip of each dataset, despite the fact it's well documented, the documentation is right but I can't see it.
Here's a screenshot -...
4
votes
3
answers
94
views
Obtaining random sample from all permutations
I have a vector of length 100 and I want to get a sample of certain size like 50, from all permutations of length 20 from elements of my original vector
My attempt so far is to first to get all ...
0
votes
0
answers
60
views
How do I combine three data frames with different columns and in R [duplicate]
I am trying to combine three datasets with different rows and columns, using Email as an identifier. I have just started using R so I am unable to figure out how to do this.
I intend to have row-wise ...
1
vote
5
answers
89
views
add suffix to colnames using a column from df in list of dataframes
I have a list of dataframes containing a column that has information and I would like to append to each of the column names in the respective dataframes.
The dataframes are held in a list like so:
set....
0
votes
0
answers
56
views
R script issue to extract the data from Google Search Console [closed]
#install.packages("searchConsoleR")
#install.packages("RAdwords")
#install.packages("googleAuthR")
#install.packages("googlesheets")
#install.packages("...
0
votes
0
answers
23
views
is there a way to do a repeated measures ANOVA with nested random effects in R? [migrated]
Basically the title. I know the anova_test() from the rstatix package can do repeated measures and does have an inclusion for error, but I'm not sure if I'm doing it correctly and I'm not including ...
0
votes
0
answers
31
views
Slingshot: no NA values but still 'Error in if (!useNames) { : missing value where TRUE/FALSE needed'
I am trying to run slingshot on my snRNA-seq data, but I keep getting the following error:
sce <- slingshot(sce, clusterLabels = sce$seurat_clusters, reducedDim = "UMAP")
Error in if (!...
1
vote
1
answer
74
views
Adding custom HTML before <div class="main-container">
I am using the includes options in R Markdown to add custom CSS and HTML to my document. My main goal is to add a banner to the top and a pretty background (not the one in the example) to the body of ...
1
vote
1
answer
37
views
Color edge links in ggraph based on specific nodes
I am trying to generate a bipartite graph where I color specific links based on certain nodes (i.e., plant species names). So far, I have been able to color the nodes of interest, but not their ...
1
vote
2
answers
62
views
How do I check one column in R for a specific word and overwrite or return that word in another column? [closed]
Using R, I want to check the ManufShortName column and if there is the word 'BLANK', then I want to return the word 'BLANK' in another column named AnalysisNotesCode in the same row.
If there is a ...
0
votes
0
answers
27
views
Problem with foreach(). Why my simulation function works outside foreach()?
I have a 300-line script that defines the function sim(pars, n.sim).
The problem is in my attempt to use more than one core of my laptop.
I run my simulation, wrapping the right parameters like this:
...
0
votes
2
answers
68
views
How to split overlapping time intervals in R, assign precedence, and fill gaps with dummy events?
I’m working with machine events data in R, where each event has a start and end time, a unique event code, and a precedence level (ordered factor). Events may overlap, and I need to transform this ...
-3
votes
0
answers
34
views
Need Help Adding Visual Diff View for Text Changes in Shiny App [closed]
I'm currently working on a Shiny app that compares posts collected over time and highlights changes using Levenshtein distance. The code I've implemented calculates edit distances and uses diffChr() (...
0
votes
0
answers
42
views
Error message "A Google Drive quota has been exceeded" [closed]
I am getting this error
A Google Drive quota has been exceeded
in Google CoLab even though i have almost 1Tb of google drive storage. I tried to wait a day, but I am still getting this error. Can ...
0
votes
0
answers
54
views
Many-to-many relationship with unique rows - how does this happen? [closed]
I am trying to understand many-to-many relationships on a theoretical level, as my problem seems to occur due to my specific data frames, which are 90,000+ rows long and hard to duplicate here.
I have ...
0
votes
0
answers
37
views
ggplot2: use dynamic nudge_y with geom_text and facet_wrap for later converting with ggplotly()
I want to plot several time series against a benchmark using R.
#Example:
library(tidyverse)
library(lubridate)
# Define the date range
date_range <- seq.Date(from = as_date("2025-01-01")...
3
votes
2
answers
106
views
How can I count lines of code in an R package?
How can I count the lines of code in an R package? I have two possible types of input:
The raw package code (my own package); I could point the function to the R folder that contains source code.
The ...
3
votes
1
answer
72
views
Problems saving in 300 dpi using ggsave
I am having problems saving my plots in 300dpi.
I have used a similar code before but now it is saving them in 96pdi
Here is a sample code (doesn't matter what type of plot it save it at the same ...
2
votes
2
answers
47
views
Needing advice on linear regression and then replacing NA's with fitted values
I am quite new to the data analytics stuff and R/RStudio so I am in need of advice. I am doing a project and asked to do:
for every variable that has missing value to run a linear regression model ...
3
votes
2
answers
107
views
In R, does tapply preserve the row order in a dataframe?
In R I have a dataframe, minimal example like this:
test <- data.frame(cat=rep(c("A", "B"), each=3), rank=c(1:3, 1:3), data1=5:10, data2=(1:6)^2)
I am using a tapply on the ...
0
votes
1
answer
63
views
Zoom to selected province, add polylines from shapefiles, and highlight clicked marker
I'm building a Shiny app that visualizes rainfall data using a Leaflet map. Here's what I want to achieve:
1. Zoom to a Province When Selected
When a province is selected from a dropdown, I want the ...
-4
votes
1
answer
59
views
Facet wrap in R for gglikert plot
i have a data frame in R with likert scale responses . Some questions are part of a broader theme. The partial data frame :
df
# A tibble: 264 × 3
Theme Question ...
0
votes
0
answers
45
views
Merging large datasets in R [closed]
For my MSc. thesis i am using R studio. The goal is for me to merge a couple (6) of relatively large datasets (min of 200.000 and max of 2mil rows). I have now been able to do so, however I think ...
0
votes
0
answers
38
views
Remove comma after sprintf statements when knitting to word [duplicate]
I am using sprintf statements for text output.
person_trend <- function(data) {
data %>%
mutate(
text = sprintf("The proportion of adults who %s %s %s between %d (%.1f%%) ...
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