Questions tagged [r]

R is a free, open-source programming language & software environment for statistical computing, bioinformatics, visualization & general computing. Please use minimal reproducible example(s) others can run using copy & paste. Show desired output. 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
27 views

Why isn't my mutate function not working for one variable?

I'm grouping data in dplyr and ggplot, but it doesn't seem to work for one variable. It computes fine with no errors but doesn't translate into groups on the graph, but my other variable does. I've ...
user avatar
0 votes
0 answers
17 views

Cannot change width of position_dodge using geom_line

I have yield data over two years that I am trying to graph with standard error bars but I cannot get position_dodge to work properly. Here is my data: Year Date Treatment Yield 2021 20-Mar ...
user avatar
  • 13
1 vote
1 answer
15 views

R Splitting String

How would I split this string by each variable like so. #Split this String (x=c(0,2), y=c(3,2), z= c(2,2)) #Get each variable [[1]] x= c(0,2) [[2]] y = c(3,2) [[3]] z= c(2,2)
user avatar
0 votes
1 answer
20 views

How to change the spacing of values in a plot in R?

I am trying to plot a chunk size in relation to run time with the different chunk sizes on the x-axis being 1000, 10000, 100000, and 1000000. However, when I create the plot using the plot() and axis ...
user avatar
0 votes
1 answer
16 views

I am trying to make a table with percentages after having used pivot.wider in R

I am currently trying to make a table with percentages after having used the pivot.wider command on a variable. htrisk is the datafile and menopaus and invasive are variables. Using the following code:...
user avatar
  • 3
0 votes
0 answers
28 views

New to R, my code seems to be executing if statements when it should not

I'm new to R coding, and the below is my first real R code. I asked a similar question yesterday, and now hopefully have what is considered to be a minimal reproducible example. I have run this code ...
user avatar
0 votes
1 answer
10 views

Adding attribute "dimensions" in a grid data

I've a very limited knowledge on R programming, I'm currently working on my thesis and I encountered an error while working with climate datasets. "Error in aperm.default(array3D, match(c("...
user avatar
0 votes
4 answers
49 views

What products are most often sold together? - Analysis exercise

I have been trying do an data analyst exercise in R with date about sales. The dataframe is like: Order_ID Product <dbl> <chr> 1 319631 34in ...
user avatar
  • 1
0 votes
0 answers
16 views

Computing cosine similarity between specific strings using dplyr

Let's say I have two datasets like this: library(tidyverse) df1 <- tibble( abel = rnorm(10), abby= rnorm(10), bret= rnorm(10)) df2<- tibble( barista = rnorm(10), beekeeper=rnorm(10), economist =...
user avatar
0 votes
1 answer
13 views

R: How can I create a line graph with shades in between each point indicating the percent change?

The goal of this is to implement the graph into a Shiny Dashboard that displays month to month net worth. The y-axis would be $, and the x axis would be any given month. I’m looking for something like ...
user avatar
1 vote
1 answer
14 views

Patchwork not aligning x axis with ggbreak

I was able to use patchwork to align two xaxis, but when I add ggbreak::scale_break(), it no longer aligns. What am I doing wrong here? Code of alignment issues follows. UnComment out scale_break() ...
user avatar
  • 11
2 votes
1 answer
22 views

cbind a column containing lists maintaining column of lists

I am trying to cbind a dataframe to a column, where some of the rows of that column are made up of lists. For example: df1 <- tibble(x1=c(1,2,3)) df2 <- tibble(x2=c(4,5,6), x.list=...
user avatar
  • 7,187
1 vote
2 answers
23 views

Insert distance in kilometers and increase text font in Shiny app

The code below calculates the distance in meters from one property to another. Note that the distance is in meters, but in addition to generating the distance in meters, I would like to generate the ...
user avatar
  • 1,079
0 votes
0 answers
10 views

make nice simple t-test (difference in means) table that can be exported to latex in R

The biggest problem with using methods such as through library(broom) library(dplyr) library(broom) output <- iris %>% group_by(Species) %>% summarise(tidy(t.test(Sepal.Width))) Is ...
user avatar
2 votes
0 answers
20 views

Using dplyr, assign unique names to groups of rows defined by multiple criteria

In my reprex below: RSA is the output of a process that is to be analyzed and whose results is to be grouped. Each RSA group has varying range of days (datenum) each is observed. var1 varies less ...
user avatar
  • 301
2 votes
0 answers
17 views

Show more digits, tsibble in R

I have read a number of ways to show more digits in R output (to R Studio display) but the methods I have reviewed do not work for a tsibble with a mixture of character and numeric columns. I am able ...
user avatar
0 votes
0 answers
16 views

R - Calculate the sum of time difference

I want to sum up the times of two rows and then find the min, max, mean, etc. But I failed at the first hurdle, because I don't even know where to start. The data looks like this: 23/07/2022, 18:59, ...
user avatar
0 votes
1 answer
26 views

Formula to calculate standard error using 95% confidence interval

I have a column containing 95% confidence intervals as shown below. I would like to calculate standard error using the formula SE = (upper limit – lower limit)/3.92 in R studio. I would like to know ...
user avatar
  • 51
-2 votes
0 answers
31 views

Web scraping csv files within a html website R [closed]

I am trying to download all of these files for my research. Since they are more than 400k, I cannot download them one by one. I have tried using the R package 'rvest' to accomplish this, but I am not ...
user avatar
0 votes
0 answers
19 views

Plot many graphs with Blastula in R

I'm trying to plot different graphs with Blastula, but just the lasted plot is showed. The code is: library(ggplot2) summary(iris) ggplot(iris,aes(x=iris$Species, y=iris$Petal.Length))+ geom_bar(...
user avatar
0 votes
0 answers
30 views

Get first weekday name of each month in a year

I want to create a vector which contains the first day of each month from the year 2015. My attempt to do this: start_2015 <- ymd_hms("2015-01-01 00:00:00", tz = "America/New_York&...
user avatar
3 votes
2 answers
32 views

R data.table cross-join by three variables

I'm trying cross join a data.table by three variables (group, id, and date). The R code below accomplishes exactly what I want to do, i.e., each id within each group is expanded to include all of the ...
user avatar
0 votes
1 answer
22 views

Points keep getting cut off, and standard fixes don't work well with facet grid on a log scale

Novice R user here wrestling with some arcane details of ggplot I am trying to produce a plot that charts two data ranges: One plotted as a line, and another plotted on the same plot, but as points. ...
user avatar
  • 1
1 vote
1 answer
20 views

How can i extract mean bioclimatic variables from unprojected grid cells?

I have a shpfile from the entire world that I converted using the as_Spatial() function for compatibility with the sp package. set.seed(27) shp <- sf::st_read("earth_gadm.shp") shape <-...
user avatar
0 votes
0 answers
15 views

gmapsdistance results as dataframe not including the original lat/long pairs

I'm using gmapsdistance package in R. I want to calculate distance/time by iterating over multiple origin-destination pairs of coordinates. My data looks like this (distance/time would be calculated ...
user avatar
  • 1,649
-1 votes
0 answers
20 views

Why does this regular expression to find words ending in "-ing" work for one example but not for the other? [duplicate]

I am using the Harvard sample sentences from the package stringr. The goal is to find all sentences that contain words ending in "ing". Here is my code: library(stringr) sum(str_detect(...
user avatar
  • 189
1 vote
1 answer
14 views

How to change download link position in a shiny app

I would like to insert the Download link right after where it says .. "the following link:" and not below, as it is at the moment. library(shiny) library(shinythemes) ui <- shiny::...
user avatar
  • 1,079
3 votes
4 answers
37 views

Finding different max between specified rows of different fields

I'm looking to find the max values of different columns based on specified rows of each column. My actual data frame is 50K columns and 1K+ rows so I can't use a loop without greatly increasing run ...
user avatar
  • 115
0 votes
0 answers
13 views

Model averaging for rma.mv objects not working using AICcmodavg package

I have a set of candidate models that I want to average so that I get one estimate and variance for each predictor, weighted by the weight of the model. I've used the following code for glm objects ...
user avatar
0 votes
0 answers
18 views

How to loop database queries

I want to search for multiple species occurrences in gbif.org using the rgbif package. To do a single search, I would use sq1 <- name_backbone("Acantholimon vedicum")$usageKey occurences &...
user avatar
  • 51
0 votes
0 answers
7 views

Counting Similar Values in SQL With Similar Time Stamps - SQLDF

I am looking at ride share data that shows a unique identifier for each rider. I am trying to find if there are riders that may benefit from a membership depending on if they travel the same route on ...
user avatar
0 votes
0 answers
17 views

Nested arrays in JavaScript same as R lists? [closed]

I am just learning some JavScript programming and I ran into the term nested arrays in JS. Are those nested arrays in JavaScript the same as lists in R?
user avatar
  • 310
0 votes
1 answer
15 views

How to print in r source stops

have a code that calls different codes inside it with source function. if an error occurs when running a source i would like to save the information of the error that appears but im not being able to ...
user avatar
-1 votes
0 answers
18 views

How to make a time series object in R when my months are grouped in pairs?

I am trying to make a time series object in R, but the data that I have is bimonthly, meaning that they are grouped in pairs (jan/feb 2019, mar/apr 2019, etc). How can I make a time series object for ...
user avatar
0 votes
1 answer
16 views

How to calculate the MSE in multiple rows of a data frame in R?

I have a data frame (datos) that has eight columns and 2006 observations: from these columns I want to calculate MSE for Pcp_Estacion and Pcp_Chirps, using the MSE function of the MLmetrics library, ...
user avatar
2 votes
1 answer
28 views

create a new column with variable but numbers are decimal instead of integer

I would like to create a new dataset I gave that code ch$n_new <- ch$new_ratio*ch$Population Now I have numbers for ch$n_new like 2.5667 or 2.1900 But I want the number 3 for 2.5667 and 2 for 2.19 ...
user avatar
0 votes
1 answer
29 views

Remove strings of different parts of levels in multiple columns

I have the following data: structure(list(ciclo = c("Basler_2020-12-01 00_34_52.441983_frames_automat.lif", "Basler_2020-12-01 00_34_52.441983_frames_automat.lif", "...
user avatar
1 vote
2 answers
23 views

How to extract dates from a text string?

Im trying to extract dates from a text string. So far I have had some progress with the anydate. My idea is to extract all dates within a text string,to a string separated by a comma, like this: str1 =...
user avatar
0 votes
1 answer
28 views

Filling empty values from web scraping with a string (rvest)

I am trying to scrape user reviews from a web site. Some of the reviews do not have body text so I am left with vectors of different lengths and getting the "arguments imply differing number of ...
user avatar
-1 votes
0 answers
26 views

Converting chr string to specific datetime in R

I would like to convert the content of my date column which is the chr class to a date time class in the format "YYYY-MM-DD". The original dataframe is the following, the dates are string in ...
user avatar
0 votes
0 answers
17 views

dgenpareto module in R jags

I have recently updated my R, Rstudio, and rjags packages. Below are the platform/versions I am running my R scripts on/with: > version _ platform x86_64-w64-...
user avatar
0 votes
0 answers
18 views

Using predict in metafor when each author has multiple rows in the data

I'm running a meta-analysis where I'm interested in the effect of X on the effect of age on habitat use (raw mean values and variances) using the metafor package. An example of one of my models is: ...
user avatar
3 votes
0 answers
24 views

What's the %??% operator used in mlr3pipelines? [duplicate]

Where might I find the documentation for the %??% operator in line 127 of mlr3pipelines's PipeOpImpute? (What package/namespace is it from?)
user avatar
  • 175
0 votes
0 answers
33 views

Recursive R function to flatten hierarchical json dataset

I have a json file that looks like this: { "data": [ { "sense": "a_lot.r.01", "frequency": 20, "level": 0, "...
user avatar
  • 520
4 votes
2 answers
36 views

can define a new column because it is factor

I have a dataset like this: risk earthquake platarea magnitude area 0.4 no 5 30 0.5 no 6 20 5.5 yes 6 20 I would like to create a new column i gave that code df$newrisk <- 0.5*df$magnitude + 0....
user avatar
1 vote
1 answer
29 views

How can I generate multiple trendlines on a single graph?

I currently have time series data in the form of abundance values over time, specifically sea turtle abundance values in the form of nest counts per year. Each individual strand of abundance values ...
user avatar
0 votes
0 answers
19 views

Why are my polygons and points from two different sources not rendering in tmap?

I am trying to create a map with a polygon layer and a point in tmap. The replication code and data can be found here. My code starts like this and creates a map just fine: ###########################...
user avatar
  • 11
0 votes
2 answers
26 views

Multiply few columns by one column in R

I have columns named X2000 till X2019, how to multiply them by column Multiplier ? for(i in 2000:2019){ df.new$X[i]=df.new$Multiplier*df.new$X[i] }
user avatar
0 votes
0 answers
14 views

Unable to connect to SharePoint list using Microsoft365R

I get the following error after authenticating in RStudio. Loading Microsoft Graph login for default tenant Error: Site 'site name' not found I am using the Microsoft365R package for R. We have ...
user avatar
1 vote
0 answers
19 views

How to fix build error? After upgrade R & RStudio to arm64 pkg with Rcpp won't build: make: "No rule to make target ..."

My first package attempt, using RStudio on an M1 macBook Pro, built, installed and worked; it used Rosetta Stone. When I learned that versions of R and RStudio could run natively were now available I ...
user avatar

1
2 3 4 5
9165