Category "r"

Why am I not getting high-resolution with ggsave()?

I'm trying to get 300 dpi images with ggsave, and am only getting the default 72 dpi. Here's an example of the code I'm using: library(tidyverse) x <- rnorm(

Multiply Columns of two different dataframes

How to efficiently multiply columns of two different data frames with same number of rows but different number of columns. I have two data sets Volumes and pri

Calculate Stock

Is it possible calculated stock using R? The formula is stock+purchase-sold. In this case first stock (row1) is 0, rg first result stockB1= 12 - 3 = 9 the secon

grouped data frame to list

I've got a data frame that contains names that are grouped, like so: df <- data.frame(group = rep(letters[1:2], each=2), name = LETTERS[1:4

How to reduce a categorical variable in a logistic regression model in R

I've created a logistic regression formula regarding mpg for various makes and models of cars. One variable "origin" was integer with : 1=American, 2=German, 3=

Looping a function/analysis in R by unique column values

I am trying to sort people in my dataset into three body-size categories (Small, Medium, Large). Consider the toy example below: library(ggplot2) library(dplyr)

How to reorder a list by the size of the data frame in each list element?

I have a list in which each element contains a data frame with n nrows. For example, dfA <- data.frame(A=c("a","a","a")) dfB <- data.frame(B=c("b","b")) d

finding peaks and peak interval for non-uniform waves

Big Update I found an inefficient, but working solution for finding peaks and peak interval, although it doesn't work for multiple groups(in the code below I us

R neuralnet package: Can't train neural network

I'm trying to use the neuralnet package to train a model on this data set. However, I'm getting the following error which I can't understand: Error: the err

Create loyalty variable in R by subtracting 2 date variables. Problem with getting the total amount of years. Football data

Im currently working for a Dutch football club and run into some problems with getting the length of relationship of certain fans. In the image below a short ov

trelliscopejs R package only one trelliscope figure visible in html file

I am having a problem rendering more than one trelliscopejs displays in an html file created with Rmarkdown. I'm using self_contained=TRUE in order to render di

Mermaid diagram line break

I cannot find how to insert a line break in long titles inside nodes. For example: library(DiagrammeR) mermaid(" graph TB A[GE Solution]-->C{ } B[

Second to last Wednesday of month in R

In R, how can I produce a list of dates of all 2nd to last Wednesdays of the month in a specified date range? I've tried a few things but have gotten inconsiste

Adding a leaflet in a precompile vignette

I'm maintaining R code in my company that is use by multiple colleagues. I decided to convert my code into a package to make it simpler to share, maintain and

Downloading file from a private repo into R

I have a zip file containing data in a private Github repo. I am writing some R code, and I wish to download the data into R. When I run the following code I ge

R - Nested list to (wide) dataframe

I currently have the following problem: I extracted some data via the crunchbase API, resulting in a big nested list of the following structure (there are many

How to set up conda-installed R for use with RStudio?

I've been trying to set up my R using conda (eventually to use with Beaker Notebook) and I want to be able to use RStudio with my conda-installed version of R

R Leaflet does not show legend when embedded in Shiny Dashboard

The map above renders perfectly fine in the following scenarios: List item RStudio Viewer Shiny app Shiny app using a minimal Shiny dashboard sceleton When

Headings not working in my R markdown file

So I recently finished my R notebook, and noticed something once i decided to knit the markdown file. None of the headings or bullet points were working! I had

PLM regression with log variables returning non-finite values error when there are no null or NA values in the data

I'm using plm package to analyse my panel data, which comprises a set of states for 14 years. In the course of running plm regressions, I've encountered a lot o