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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
5 views

vectorization in xts is there a simple solution

set.seed(2) library(xts) x <- sample(1:5,10,replace = T) x.xts <- xts(x, order.by = seq(as.POSIXct(Sys.time()), length = 10, by = "min")) I have xts object x.xts and i want apply to ...
mr.T's user avatar
  • 301
0 votes
1 answer
20 views

HOW TO REPLACE na TO 0

Sorry, I'm a complete beginner. I want the data of a certain table, but because I divide 0 by 0, I get NA. How can I change NA to 0? india$ruppi.per.hourwork<-india$Family_Labour__Rs__/india$...
RAZ ITZHAK's user avatar
0 votes
0 answers
8 views

Modify linetype of waterfall plot (shapviz package)

I am trying to modify the linetype of sv_waterfall() of the shapviz package with no success. I want to customize my shap's waterfall plot by eliminating the linetype (by supllyinglinetype=none, but it ...
Moh Zulfajrin's user avatar
0 votes
0 answers
17 views

I do not know how to change double dots with after_stat() in may R code chunk in ggplot2

I want to change ..dx.. and ..dy.. to after_stat() function in my code below because in the newest version of ggplot2 it is deprecated. ggplot(data = europe_wind_stream) + geom_sf( data = ...
Beycan Hocaoglu's user avatar
0 votes
0 answers
11 views

Getting Java error when running driver drake

I ran into a problem, while running 'driverdrake' within 'renv', It state that Java is not available. I have updated the java path and using jdk-18.0.1.1. please help me resolve this issue. Below i ...
Aritra's user avatar
  • 1
0 votes
0 answers
23 views

Error in match.arg(opt.crit) : 'arg' must be NULL or a character vector

I have an code but it have an error In R, I do not know how to run it. enter image description here And here should be run out like this enter image description here library(forecast) library(itsmr) ...
zehao li's user avatar
0 votes
1 answer
31 views

How to choose only two years in R using lubridate (not including years in between)

I am using RStudio and a semi-large data set in which I want to only select the years 2016 and 2023 in the data set in the column observation_date. I tried using the lubridate to do this. However, I ...
user23049731's user avatar
0 votes
1 answer
18 views

r time range plot before and after

May goal is to generate a time range plot like this. This is the toy dataset Group1 N Year A 10(10) 1999-2001 B 83(56) 2001-2004 C 100(94) 2006-2007 D 53(51) 2009-...
Ahir Bhairav Orai's user avatar
0 votes
1 answer
26 views

How to create adjacent plots on a boxplot in R?

I am newish to r/studio and am unsure how to tackle this problem. Let's say I have a simple table like this: Year Property 1 Property 2 Property 3 2023 12 30 23 1995 20 39 28 1972 21 44 35 ...
J Jenson's user avatar
0 votes
1 answer
27 views

How do you conditionally format dataframe objects?

I am trying to conditionally format these precinct names depending on whether the ward comes up as "0" or not but I keep running into object type issues because they dataframe objects and ...
Fred Ditzian's user avatar
0 votes
1 answer
24 views

Is there a way to generate an officer docx as a pdf without the use of libreoffice?

Due to the data security rules at my job, I can't install certain applications. I was wondering if there was a simpler way to generate word docs as a pdf before R outputs the document.
Dontai Lewis's user avatar
-1 votes
0 answers
18 views

I'm not understanding .pred_class in classification (using logistic regression)

I have a pretty simply problem where my outcome is binary and I am trying to use logistic regression (using tidymodels) to classify based on a few predictors (some of which are well-known as good ...
inprogress123's user avatar
0 votes
0 answers
29 views

How would one go about converting a list with differing numbers of rows to a dataframe?

I'm trying to convert a list of data from a series of files into a dataframe. I'm using the tibble package to do so. mydata <- as_tibble(mylist, .name_repair = "universal") This method ...
thefriendly_plague.doctor's user avatar
0 votes
0 answers
15 views

When loading the heplots, the R shut down

I have a problem with the package "heplots". When I load this package. The R will show the stop in the upper right corner and shut down. After loading the "broom" package, the ...
官政宏's user avatar
0 votes
1 answer
17 views

How do I run repeated measures ANOVA on files of different lengths in R?

I ran a within-subjects study with 40 participants trying out all three conditions. I have three output files per participant, one for each condition. The files contain a column of their current error ...
onemorecoder's user avatar
0 votes
2 answers
50 views

r retain non zero rows in case of duplicates

I have a dataset with duplicate rows if we group by two columns ID Group Value 1 z1 0 1 z1 0.81 2 z2 2.89 2 z2 1.53 3 z1 ...
Ahir Bhairav Orai's user avatar
0 votes
0 answers
7 views

No zero exit status error when running install.packages on Hmisc

I keep receiving the no zero exit status error whilst trying to install Hmisc, tried updating everything (OS, R studio etc), no result. Other packages run, just not this one. This is the error i ...
revenue_geek_124's user avatar
0 votes
0 answers
20 views

"shinycssloaders" don't work with an oberveEvent that has a button as input

I'm new with shiny, but I would want to make a loader work while the action of a button is running. My code is something like what is shown below: library(shiny) library(ggplot2) library(bslib) ...
strikestack's user avatar
0 votes
1 answer
39 views

How to reverse legend (labels only) so high value starts at bottom?

Very similar to How to reverse legend (labels and color) so high value starts at bottom? except keeping colours the same: I have a ggmap with raster values that to from 0 to 100. For various reasons, ...
dez93_2000's user avatar
  • 1,774
0 votes
0 answers
6 views

Why does adding mean_se to ggpubr::ggbarplot give proportion above 100?

When I plot ggbarplot stacked bar, both bars add up to a total value of 6 (as expected). However, when I add error bars to demonstrate the variation within each group using add = "mean_se", ...
MeganCole's user avatar
0 votes
1 answer
25 views

Create New Columns by Dividing Values from Other Columns Based on Conditions

I am trying to create new columns that would look at the proportion of income for different expenses. This is what my data looks like: df_inp <- read.delim(text="Individuals| quarter | wage | ...
becky_45's user avatar
0 votes
2 answers
28 views

geom_facet with scales = 'free_y' generates y-axis texts in empty plots

I have a following ggplot2 R code that creates state-specific plot using geofacet package: ggplot(plotdf, aes(x = year, y = value)) + geom_line(aes(color = group1), linewidth = 0.6) + ...
Dai's user avatar
  • 63
0 votes
0 answers
20 views

Is their an R World Map that delineates by overseas regions?

Does anyone know of an R World Map that designates not just by country and territory (e.g. U.S. vs. Puerto Rico are two separate entries in the 'sf' package's 'ne_countries()') but ALSO by parts of ...
Dana Grieco's user avatar
0 votes
0 answers
18 views

How to plot Learning Rate and Epoch when training a CNN?

I am trying to use a cosine-based decay schedule to improve the accuracy of my CNN. I want to visually see the changes that are made to the model's learning rate by this schedule throughout the ...
Mateo del Rio Lanse's user avatar
0 votes
0 answers
39 views

How does `ggdist::stat_halfeye()` scale posterior predictive density

My goal is to calculate a 95% prediction interval using a Bayesian zero-inflated beta model in R. I have had no issues doing so but when I plotted the posterior predictive density using stat_halfeye() ...
Stefan's user avatar
  • 737
0 votes
0 answers
7 views

RSelenium Setup Error: "argument is of length zero"

I'm trying to learn Rselenium to scrape web data, but I can't get past square one. Here's my code: install.packages("RSelenium") install.packages("rvest") install.packages("...
Lucky_will's user avatar
0 votes
1 answer
34 views

Why is the output of my mutate function 26 when it should be 29? [duplicate]

The minAB0 column should output as described in the mutate() function. data <- data %>% group_by(Sample) %>% mutate(minAB0 = min(XD_VD+SE, value)) # why is this outputting a different ...
kansasliketheband's user avatar
0 votes
0 answers
31 views

HMM R package Error in if (d < delta) { : missing value where TRUE/FALSE needed

I am trying to use HMM package in R. I want 4 hidden states, and my observed values range from 2 to 15. I can initialize the hidden model without any issues: if (!require(HMM, quietly = TRUE)) { ...
Luan Vieira's user avatar
1 vote
1 answer
35 views

stat_poly_eq erroring when using grouped data in a ggplot

I'm struggling to get stat_poly_eq() working when I've got grouped data. Seems to work fine when there are no groups. Here's some demo data to show the error. demo_data <- structure(list(dose = c(0,...
Mike's user avatar
  • 959
0 votes
1 answer
29 views

r retain duplicates after group by not min value

I have a dataset like this. ID Group Value Col3 1 z1 1.29 1 1 z1 0.81 1 2 z2 2.89 1 2 z2 1.53 2 3 z1 0.13 ...
Ahir Bhairav Orai's user avatar
1 vote
0 answers
37 views

How to adjust every column of a dataset according to 3 (confounding) variables of the same dataset?

I have a dataset with metabolic data for 2 patient groups (with and without a disease). 40 Patient IDs in rows. Usually metabolic data is heavily influenced by age, sex and BMI. Unfortunately, one of ...
c_dinosaur's user avatar
0 votes
0 answers
14 views

Create a shiny app that plots one of two plots depending on an input

I'm trying to create a shiny app that will plot something if a user selects one input and plots something entirely different if the user selects something else. Below is a very basic reproduction of ...
Dan W's user avatar
  • 19
0 votes
0 answers
20 views

Best way to handle numerical integration error iteratively in R?

Consider the following numeric integral in R: integrand = function(u){log(u) * u ^ (2 * (H - 1)) * (exp(a * u) - exp(- a * u))} integrate(f = integrand, lower = 0, upper = 100, rel.tol = ...
Mr Frog's user avatar
  • 338
0 votes
0 answers
10 views

Solving: Error: ctree model: Mismatch in number of predictions and test labels

Essentially, for my program, I am supposed to create a script that takes input from a csv file "bank.csv", and with it, I am supposed to plot bar graphs comparing the accuracy, precision, ...
SirTubsAlot's user avatar
0 votes
1 answer
51 views

Cleaning Data Task in R

Last week I failed at an exam because of one task. I would be very glad if someone could identify the mistake in my code and help me make sense of what I could improve. Specifically, I wonder if the ...
TMM's user avatar
  • 1
0 votes
1 answer
15 views

Importing shapefile from CMEC Zoogeographic Realms and Regions paper, in R

I am trying to import a shapefile of 11 biogeographic regions in R. The data containing the shapefile I am interested in are available here (https://macroecology.ku.dk/resources/wallace) under the ...
Bradley Allf's user avatar
-1 votes
1 answer
33 views

R Reshape Wide to Long with Stubs

HAVE = data.frame(STUDENT=c(1,2), CLASS = c(100,200), T1CHE=c(95,NA), T2CHE=c(13,66), T3CHE=c(99,1), T1CHES=c(...
bvowe's user avatar
  • 3,138
-1 votes
0 answers
12 views

Error with ensembling modelling function for a Species Distribution model

I have to do a SDM for an assignment so I tried to run this code: cor.ens1 <- ensemble_modelling(algorithms = c("GAM", "RF", "GLM"), ...
Joana 's user avatar
0 votes
0 answers
30 views

comput the sum of small pixels within bigger ones in two rasters?

If I have 2 rasters: library(raster) rr1 <- raster(ncol=10, nrow=10) rr1[] <- runif(ncell(rr1)) rr1[1]=2 rr1[10]=2 rr1[50]=2 ...
Tpellirn's user avatar
  • 776
0 votes
2 answers
35 views

In R I want to add everything after an underscore to a string in a previous row so that they each have the same string after said underscore

Say I have a column that has the following; c("Q9NZ", "Q69Z_1036_1037_1_1_S1036", "A3K8", "P123_567_789_1_1_T567") I want the output to find the underscore in ...
John H's user avatar
  • 9
0 votes
0 answers
9 views

Code in heatwaveR bringing up error message "time must be given as character strings"

I'm trying to run some code from a vignette that is accessing the NOAA OISST data on the ERDDAP server (https://robwschlegel.github.io/heatwaveR/articles/OISST_preparation.html). I have run this code ...
Ktsmith39's user avatar
0 votes
3 answers
33 views

Is there a way to shorten long intergenic regions in gggenes?

I'm visualizing a series of gene clusters with gggenes, and was wondering if there is a built-in functionality or workaround to shorten long, unannotated regions between genes of interest. Here's the ...
Izzy's user avatar
  • 53
1 vote
1 answer
22 views

Append MSE value from random forest iterations varying mtry values into a data frame in R

I am building a random forest. I am trying to append the MSE values from the model into a dataframe while varying the mtry values. I am attaching mock data and a mock RF (not my real analysis, solely ...
shollaback's user avatar
0 votes
1 answer
33 views

Can I add a randoma effect to stat_poly_eq() in ggplot?

I am interested in adding a random effect to a ggplot using stat_poly_eq(). library (ggplot2) library(ggpmisc) data (mtcars) mtcars$gear <- factor (mtcars$gear) mtcars$cyl <- factor (...
JamesR's user avatar
  • 71
0 votes
0 answers
20 views

How to get reliably a complete sessionInfo in mclapply/pbmclapply?

I'm using pbmcapply::pbmclapply (in Rscript, i.e. non-interactive if that matters) to see a progress bar during multthreading. Now I tried to pass sessionInfo() as an attribute and noticed that "...
jay.sf's user avatar
  • 63.1k
0 votes
0 answers
18 views

test if rmarkdown format is rdocx_document similar to knitr::is_html_output()

Depending on format output, I want all plots in rmarkdown to be a certain size if the output is word (officedown::rdocx_document:) and a different size if the output is html (bookdown::html_document2:)...
user63230's user avatar
  • 4,189
1 vote
2 answers
38 views

Optimising row-wise function on data.table

I am having difficulty creating a fast data.table solution for a keyed join on numeric ranges. I have the following input data: coverageTable <- data.table('position' = c(1:6), ...
undercover_camel's user avatar
0 votes
0 answers
27 views

Equal group randomization in groups already assigned treatment

I have a list of 80 subjects already randomized into 4 groups (1-4). Now, I want to introduce a crossover design so each subject will eventually be in all 4 groups. Tried to do this with the sample ...
Elizabeth's user avatar
-8 votes
0 answers
43 views

Exam prep for R exam [closed]

https://docs.google.com/document/d/15-4RqJwbgQ3tfRcyfkPGw2RO6o8h6X6XG-8uMKQyNhw/edit?usp=sharing https://docs.google.com/spreadsheets/d/1LJWhb_OdUZvuCav4G541x2Akgf-feTstSqEolIwC7-s/edit?usp=sharing Hi,...
Quinten Steijns's user avatar
0 votes
1 answer
8 views

Error with EUtilsSummary in RISmed package: 'length = 4' coercion issue

I'm encountering an issue while using the RISmed (v:2.3.0) package in R(v:4.3.2), specifically with the EUtilsSummary function. I've followed the instructions provided, but I'm getting the following ...
Francisco's user avatar
  • 111

1
2 3 4 5
10018