Category "r"

How to join (merge) data frames (inner, outer, left, right)

Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3))) df2 = data.frame(CustomerId = c(2, 4, 6), State =

does openxlsx offer bullet/key point functionality?

I need to output, using the openxlsx R package, some text rows in bullet point format. There doesn't appear to be a createStyle() option for doing this. Is anyo

Question when drawing a graph in r(dodge or geom_line)

I want to express the frequency of each column (a,b,c,d,e) in a graph of (t) for each group. I don't know what to do. As shown in the figure, the data was selec

How to aggregate a categorical variable with 20 levels in hierarchical/ grouped forecasting and use it at external regressor

Fellow contributors, I have been working with a hierarchical time series, concerning a set of identical products in a number of stores. For this purpose when we

In R Shiny, use stats::setNames to assign names to vector elements and then retrieve the name attributes in the server side

I have a shiny app that displays data from a database, in which variables are assigned codes (e.g., "TMAX" for maximum temperature, "GDD" for growing degree day

ggsankey: Error: `n()` must only be used inside dplyr verbs

I'm new using ggsankey. I have the following data t1 <- sample(x = c("Hosp A", "Hosp B", "Hosp C","Hosp D") , size = 100, replace=TRUE) t2 <- sample(x = c

How to use created functions argument inside the code?

When I create a function and use arguments as variable names in group_by() function there is error: comb <- function(z,x,y) { df <- z %>% group

Get chi squared from cartesian points

I have a table with x, y columns x y 10 12 23 24 12 43 34 15 74 18 ... How can I know if they have a random distribution or if there is a dependency bet

How to draw rectangle around map area in R?

I have a map of the Northern Hemisphere centered around North America. I would like to draw a red rectangle around the USA (this is part of an inset map) howeve

R nls model fails to converge on Linux, not on macOS

I have a grouped/nested data frame on which I want to run an nls model fit for each group. This code used to work fine on one machine. Running it on another mac

Plotly R: highlight the hovered label in pie chart and grey out the other labels

Dataframe: df2 = data.frame(value = c(9, 2, 7, 3, 6), key = c('ar', 'or', 'br', 'gt', 'ko')) And this is the code to generate the pie chart: d

R: how to calculate fraction of empty rows in all columns of a large matrix?

I'm working with single-nuclei rna sequencing and I made a matrix of a subset of genes across all features that shows the counts per gene for each of them. I wa

Keyword repeated multiple times in context from string in R

I have a dataset (z) with strings which are very long in z$txt. I also have a dictionary (incd) of keywords that need to be identified. In the column z$inc.term

Show true unknown count based on question logic

I'm working with surveys where if a specific answer is provided, a follow-up question is given. For example, if the answer to q1 is "yes" then q2 is asked. Howe

Change decimals for proportion of variance displayed in autoplot PCA

I would like to change the number of decimals for the Proportion of Variance displayed in the axes of a PCA plot using prcomp() and autoplot(). By default it's

How to hide, or at least customize colorbar in plotly scattergeo in R

I want to create a scattergeo plot with markers for capitals. These markers are sized and colored regarding database values. If I use the standard colors, every

Error: object not found after being defined in R

I have just started using R, and I seem to be falling over at the first hurdle... I have defined an object in my R project which is the csv data for a file I ha

R: ggplot with 6 different groups: Have 5 solid lines and for one group a dashed line

I have the following data: structure(list(Date = c("01.08.2018", "02.08.2018", "03.08.2018", "04.08.2018", "01.09.2018", "02.09.2018", "03.09.2018", "04.09.201

Open CSV data in tableau

I have had problems uploading the following file to Tableau: https://www.kaggle.com/datasets/shivamb/netflix-shows/download When loaded it looks like this but

Change column name with tq_get() in Tidyquant

I'm using the tq_get() function in Tidyquant to retrieve economic data from FRED: library(tidyquant) library(tidyverse) consumer_price_index <- 'CPIAUCSL'