Category "r"

How to find the Consecutive Days from a list of dates or data frame

I need to find consecutive days from the data frame but I am having some trouble trying to find them. I tried R, Excel, and Python but still couldn't find the s

Create a new column based on multiple conditions in other columns in R

I have a data frame that has this structure: dat <- data.frame(col1 = sample(0:3, 10, replace = TRUE), col2 = sample(0:3, 10, replace = TRU

Converting column names so they can be put in an numerical order

I am trying to expand on this answer, by creating a solution that works both on the new_dat and the old_dat. New Data new_dat <- structure(list(`[0,25) east`

Using a keyword between list names to apply a function between elements

I have a list l1 that have file names for each of the list elements. I also have a second list l2, that have some of the same components in the names of the lis

Using add_header_row from flextable to create columns of varying widths

I have data as follows: dat <- structure(list(rn = c("type_A", "type_B", "type_C" ), freq = list(c(0, 0, 0, 5, 7, 16, 28), c(2, 1, 0, 5, 0, 8), c(0, 0,

How to get rid of an error while using the mle function

I tried to run MLE in r using the mle function. It was working fine but I encountered the following error all of a sudden. Can anyone help? Error in if (!all(lo

Increase space between two discrete values in a ggplot2 plot in R

I am trying to figure out how to add space in a plot between two discrete values on the x-axis. For example, in the plot below, I'd like to keep the same spacin

How to resize plot_ly plot in R

I have been trying to plot a surface from the following data z = structure(c(-0.901395069908367, -0.889270928722939, -0.860498522734513, -0.81162341264254, -0.

Surface in plotly does not cover all data, leaving a gap between surface and highlight

I am using a plotly surface plot with data that has some missing values. As you can see in the example below, I am using highlight lines to show the surface doe

R RestRserve Add Etag to static path

Let's say I have a REST API using RestRserve like this, is there a way to add an Etag to enable caching on cloud services? writeLines("Hello World", "myfile.txt

How to remove substring starting with RT and ends with ":"

I have a dataset with a column consisting of tweets. Some tweets are retweets, which start with RT @username: ..... I would like to remove this part of the stri

select(column, (contains()) not showing results

chase_2021 = chase[c(143:1020),] paychecks = chase_2021 %>% select(Posting.Date, Amount, Description, starts_with('CVS'), ends_with('PPD ID: 995338

R generated graph from Kaggle notebook that's completely different from the graph I get from RStudio

The following code creates a bar chart for my analysis: ggplot(ctd_monthly_num_rides, aes(x=factor(month,level= c('January','Februa

How to draw double coordinate CDF and PDF with R

I want to plot a picture with cumulative distribution function (CDF) and probability density function (PDF),which has a unified x-axis and y-axis with re

How to fill area below geom_line plot in ggplot with geom_rect?

This is my plot: library(ggplot2) economics <- economics %>% mutate(year = year(economics$date)) ggplot(economics,aes(year, unemploy))+ geom_line() +

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