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

Why is the Quanteda package extremely slow on a MacOS Venture M2?

When I run the tokens() (Quanteda) function on a MacOS Venture M2 10-core 16 GB RAM 512 GB, this function is extremely slow. For example, for a corpus with only one text document it takes 0.08 seconds,...
  • 1
3 votes
0 answers
11 views

Stylometry with R-Studio: Error with command oppose from package "stylo" - why is my corpus not usable?

I run a stylometric analysis of poetry in R Studio using the package "stylo". I want to compare two sets of texts via function oppose. I created subdirectories in my working directory for ...
1 vote
1 answer
16 views

Align r-stack layout tables in revealjs Quarto

I would like to fragment two Kable tables in a .r-stack layout. The problem is that when the second table got a colored value, the table doesn't align well anymore after overlaying so it shows the ...
  • 32k
0 votes
0 answers
9 views

How to get data in R from a very large sql table using a loop

I need to get via ODBC, data from sql table into R for further work. I do so: library("RODBC") library("sqldf") library(here) library(knitr) #connect to sql dbHandle <- ...
  • 2,945
0 votes
1 answer
16 views

R: Including help of a function into Quarto document

The following r code gives the output example( topic = mean , package = "base" , type = "html" ) Wondering how to add similar kind colored ...
  • 22.4k
0 votes
1 answer
17 views

How to split dataframes of a list then join them based on a variable

I have scattered data sets with different observations from different years in a list I want to group observations from the same years in the same datasets. mydata1<-data.frame(ID=1:5, year=c(2011:...
  • 1,091
0 votes
1 answer
7 views

ggplot: separate positions of colorbar and color legend

I am trying to create a ggplot scatter plot with continuous fill and discrete color. I would like to place the colorbar at the bottom and the color legend inside the panel (see image below). ggplot(...
0 votes
1 answer
14 views

How to build subset of datset with files showing specifc pattern in file names using for loop index

I have many files to analyse all with names as model as follows (for ease sake, I would report simplified reprex here): A_(ele)_c.xls A_(ele)_d.xls A_(ele)_e.xls B_(ele)_c.xls B_(ele)_d.xls B_(ele)_e....
  • 1,093
0 votes
1 answer
16 views

Logistic regression results with and without odds ratio in modelsummary

I like to show logistic regression with and without exponentiated coefficients side by side with the modelsummary package. The package produces great html output. It comes with an easy option to turn ...
  • 2,112
0 votes
1 answer
14 views

How to simply start mapping in R?

For the first time, I want to do mapping in R, something very basic to start with. For example, draw the map of a country and add points according to GPS coordinates that I have in a datatable. I ...
  • 461
0 votes
0 answers
11 views

Login Shiny with Wordpress authentication

I deployed a shiny app to shinyapps.io. For now there is no authentication. I planning to use firebase for authentication. I have Wordpress web site. I'm using firebase to login there and I want to ...
1 vote
3 answers
18 views

Issue creating new variable with mutate R using strsplit

I am trying to create new variable using mutate from column. I am using strsplit to perform some string operation to create new variable contents. But it is not working as desired. myDF = data.frame(...
1 vote
2 answers
21 views

How to change values in certain columns based on if the column names contain a string in another column in a dataframe for individual ids in R

Here is a dataset: df <- data.frame(id = c(1, 2, 3), substance = c("A,B", "B,C", "C,D"), years_in_recovery.A = c(2, 4, 4), ...
  • 11
0 votes
0 answers
11 views

Paired sign test with weighting

In R, I am using the survey package to conduct these tests on paired data: Weighted Wilcoxon Signed Rank test Weighted Sign test However, I am struggling in doing them. By defining a design and then ...
0 votes
0 answers
8 views

Problem specifying arguments when using "optim" for MLE

I am trying to implement Maximum likelihood estimation for the following 2-parameter Beta-Poisson model Working through other solutions in StackOverflow I came to the conclusion - possibly ...
0 votes
1 answer
20 views

How to convert a date character vector to Date format while keeping only year and month information?

I have a character vector containing dates in the format "YYYY-MM", such as: date_vec <- c("2020-01", "2020-02", "2020-03", "2020-04") I want to ...
  • 347
0 votes
2 answers
20 views

R package: namespace ‘rlang’ 1.0.6 is already loaded, but >= 1.1.0 is required [duplicate]

I want to use package semPlot and I get the error message as follows. library(semPlot) Error: package or namespace load failed for ‘semPlot’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck =...
-2 votes
0 answers
32 views

Which is faster, computation done directly in php, or an api call, calling compiled C++ code? [closed]

I have a webpage that does some computation (basic arithmetic operations mainly). I have made an R package that does the same, where the arithmetic is done in C++. The R packages is callable from a ...
0 votes
0 answers
11 views

Applying text formatting to group name labels in gt package

How can we target individual groupname_col labels for text formatting in gt() package when multiple groups are specified? In the example below, I'd like to make the "group" variable bold, ...
  • 23
4 votes
1 answer
28 views

Why does plm not like my dplyr-created dataframe?

If I perform simple and seemingly identical operations using, in one case, base R, and in the other case, dplyr, on two pdata.frames and then model them with lm(), I get the exact same results, as ...
0 votes
0 answers
12 views

Equivalent of raster::deratify in terra r package

I have a raster with a raster attribute table (RAT). I want to generate a new raster using one of the column values of the raster attribute table. It can be done using raster::deratify as described in ...
  • 6,732
0 votes
1 answer
24 views

Including a jump from 0 to 1500 in my y-axis

I want to include a jump in my plot. Thy y-axis should start from 0 but the there should be a break which goes to 1500 and from there in 100 unit increments up to 2000. This works in my code, but the ...
  • 1
0 votes
0 answers
11 views

Installation of Seqminer

I am trying to install a package called "seqminer" in Rstudio on windows platform. Seqminer is a pre-requisite of another package that I want to install. But I am getting the following error ...
  • 53
0 votes
0 answers
28 views

Preserve names when factorizing a character variable in R

I have df like this one: df <- tribble( ~country, ~status, "American Samoa", "non-UN member", "Argentina", "UN member", "Austria", "UN ...
  • 199
2 votes
3 answers
51 views

Match the last triple underscore following a character or number

I'm struggling to figure out a regex that can match the last triple underscore in a string that is preceded by a letter or number. Eventually, I want to be able to extract the characters before and ...
  • 16.7k
0 votes
0 answers
10 views

Is Excel Evolutionary Algorithm similar to DEoptim in R?

I am trying to solve a minimization problem using DEoptim in R. Previously, I used Excel's Solver tool, particularly the Evolutionary Solver technique. But the results from DEoptim don't match and are ...
0 votes
1 answer
19 views

List(i : j) gives me a list of size 1 when i-j > 1

I'm trying to create a function that returns an nxn matrix with has values of row index -column index for each of its elements. e.g. n = 3 0 -1 -2 1 0 -1 2 1 0 ijMatrix <- function(n) { temp &...
0 votes
1 answer
28 views

How to create a diverging bar plot that diverges from a non-zero value in R?

Using R, I want to create a horizontal diverging bar plot which diverges from a specified average value. Normally bar plots are diverging from 0, but how can I make a bar plot which diverges from a ...
0 votes
0 answers
7 views

Weighted chi square and t-test

I want to perform chi square test and t-test between variables of my weighted population. How can I perform these tests using the weights I have calculated? For example: library(cobalt) library(...
0 votes
0 answers
6 views

Is there a way of arranging symbols in *lattice::segploplot* pch keeping specific order in R?

Hy guys, I'm trying to arrange symbols of my lattice::segploplot in same order as sample size legends. No success until now? Does anyone knows how to help me? Header of the image bellow has sample ...
  • 96
0 votes
0 answers
12 views

How to create a R function that replicates MS Excel's STDEV.S with IF?

In R I'm looking to create a row calculation that finds price standard deviation based on Product type and a date range based on Order_Date. In the example from Excel, I find the standard deviation of ...
  • 13
1 vote
1 answer
22 views

Colour area of Polygon in ggplot based on a threshold value

I have some data that I plot using the geom_polygon in ggplot (data pasted at the end). # GGplot: anomaly for ONI region 3.4 -------------------------------------- library(ggplot2) library(tidyverse) ...
0 votes
0 answers
6 views

Trying to assign a spatial reference to a polygon in R

I am trying to generate randomly shaped and sized plots that will cover 85% of a raster image. This is what I have so far, but I keep getting an error message. I've tried a bunch of different ...
  • 21
-1 votes
0 answers
19 views

I need to create a factor variable called Full_Month whose levels are the full names of the months

It gives me the following error: I tried the following code: txhousing |> mutate(Full_Month = factor(month(date), labels = c("January", "February", "March", "...
0 votes
0 answers
12 views

Clipping polygons using other polygons. (sf objects in R)

I have fire polygon and ecoregion data. I am attempting to remove all fire polygons that do not fall into the specified ecoregion. I had tried using st_crop and st_intersection, but it keeps returning ...
0 votes
0 answers
18 views

Adjust positioning and precision of quartile labels in ggplot2 boxplot

I have the following codes: quartiles5 <- datalong5 |> group_by(Year, new, variable) |> reframe(y = quantile(value, c(.25, .5, .75), na.rm=TRUE)) CAGR<-ggplot(datalong5, aes(x=Year,...
  • 11
0 votes
0 answers
9 views

need finite 'xlim' values error with dlookr package

I'm trying out the dlookr package for EDA and I'm exploring the package with the ames dataset. I'm getting the following error when I try run the out of the box report: transformation_paged_report(...
  • 2,465
0 votes
0 answers
8 views

Dependent Variable with Multiple Survey Questions

I am attempting to create a dependent variable that considers 4 survey questions all of which have dictomous outputs. However, I am unsure what would be the best practice for doing this. Is creating ...
0 votes
0 answers
7 views

Highlighting when a value is the same for at least 3 consecutive days (represented by either date or YDAY)

I have a dataframe with many individuals over multiple years where I have the total distance an individual ID has moved per day. I am trying to find the julian days that an individual moved less than ...
1 vote
1 answer
18 views

tidyverse- Is pivot_wider() only way to summarize selecting specific row values?

I need to summarize an index of testing results from tidy data. For each group, I need to do a weighted sum of specific values to return a index value. I'm used to using group_by() and summarise() and ...
0 votes
0 answers
9 views

how to use oneDAL's Naive Bayes classifier in R?

I have a Xeon Phi card and I'd like to use it to speed up my Naive Bayes classifications in R by using Intel's DAAL libray. I found an article which describes how to use Intel DAAL: https://www....
0 votes
1 answer
14 views

cross tabulation where rows corresponsd to unique values in x and columns correspond to unique values in y in R

long time lurker, first time user. In short, I am looking for a function similar to "crosstab" in Matlab, but in R. In the matlab example (this is taken from Matlab's cross-tabulate page), ...
0 votes
1 answer
10 views

How to download nycflights 13 package?

I am failing to download the nycflight13 package. I tried to download and install nycflights13 package. A big file with nycflights13 has been downloaded in my computer, however I am still failing to ...
1 vote
0 answers
28 views

Fast rolling correlation between two columns of data.table

In the data.table below, I am trying to find a 7 days rolling Spearman correlation between the columns value1 and value2. temp_dt = structure(list(date = structure(c(19390L, 19391L, 19394L, 19395L, ...
  • 1,532
0 votes
1 answer
15 views

For R install.packages, can a default CRAN mirror or repo be specified with an environment variable?

Normally I install R packages with: install.packages("my_package", repos = "https://cloud.r-project.org") Is it possible to specify a CRAN mirror with an environment variable ...
1 vote
0 answers
20 views

how do I extract the 2 sub element of every part of a list even when some parts don't have a second sub element?

I have names in a list and each part of the list has 1 to 16 names in it. the list format is below. [[1]] [1] "Peter A. Christensen" "Mathis Eskjær" "Peter Lyngby" ...
  • 11
1 vote
1 answer
26 views

Show tab that was hidden from another Shiny module

I'm attempting to display tab2, from within a server module, upon clicking a dynamically generated button. Although the message is displayed, I'm unable to understand why the tab2 is not appearing ...
  • 121
-1 votes
0 answers
10 views

How do I fix an MS Word error that won't let me open a .docx created bookdown/knitr in RStudio on a Mac?

Sometime between 7-Apr-2023 and today (14-Apr-2023) I lost the ability to open a word document knit in RStudio using bookdown on my Mac. I've searched the internet and got nothing specific to this ...
  • 121
0 votes
1 answer
27 views

Pairwise comparisons within the same column in R

I have certain response variable (biomass) that I am analyzing across a series of environmental conditions that were retrieved from different papers. Example dataset: Paper Biomass Condition P1 10 ...
  • 3
1 vote
1 answer
17 views

How to subset items in a list

Consider. li <- list(c(1,1,1), c(2,1,1), c(5,1,0)) ## [[1]] ## [1] 1 1 1 <-- 0 modulo 3 ## ## [[2]] ## [1] 2 1 1 ## ## [[3]] ## [1] 5 1 0 <--- 0 modulo 3 I ...
  • 1,009

1
2 3 4 5
9745