Category "r"

How do you populate missing dates for lag?

Say that I have a dataset. date <- c("2004-02-01", "2004-03-05", "2004-08-09", "2004-08-13", "2004-10-20", "2004-11-02", "2008-01-05", "2008-02-03", "2008-08

In a dashboard made with R, how can I filter/unfilter based on selectInput?

I have created a simple dashboard (link here) to display some data in R using selectInput. How can I activate/deactivate a filter reactively, so that the output

Customize R linters in VSCode

I'm trying to customize the linter settings in VSCode for R but I'm a little confused. I've checked just about every source available, from SO questions to the

How to get the names of factor levels corresponding to fixed effect regression coefficients for a GAM in R?

I have a gam in R (mgcv package) with 7 parameters, and one of them is a fixed effect with 30 levels (30 names). I want to analyse the regression coefficients f

The cause of "bad magic number" error when loading a workspace and how to avoid it?

I tried to load my R workspace and received this error: Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning mes

pivot_longer multiple variables of different kinds

I am trying to find a simple way to pivot_longer a dataframe that has multiple columns containing different data for each case. Using multiple names in names_to

How to make labels in boxplot vertical in R

I have too many labels on the x-axis. How can I project them vertically? I can't find the right arguments... boxplot(df$y$x, data=df, drop = TRUE, main = "Bo

How can I subset a list in r by extracting the elements that contain a string? [duplicate]

I have a list: mylist<-list() data<-1:162 listlabel<-c("a","bpt","b","fpt") for (i in 1:4){ label<-listlabel[i] mylist[[label]]<

RStudio error in windows: Running pdflatex.exe on file_name.tex.. (exit code -1073740791)

I am using Rstudio in windows 10. I am triying to create a pdf from a .tex file. However, when I compile the PDF, the following error appears: Running pdflatex.

Coin flip probability

I'm wondering what I should be doing here (please refer to image). I have already defined two vectors which are k=c(0,1) and v=c(runif(2,0.3,0.7)) where alpha=v

Extracting rows based on more than two partial strings that must all be part of the string

I want to extract rows that must contain two or more partial strings. For example, suppose I have the following data.table df <- data.table(player = c('A', '

Shiny datatable mode editable - restrict specific columns AND ROWS

I would like to restrict editable mode in datatable for columns and rows. For the moment, in this minimal example, I can edit only specific columns but it doesn

Using grep to match variables in one column to a string of text in another column [duplicate]

I need to match a string in the first variable with a string in the second variable and then return true or false in the third column. Here is

Create a column includes all confidence intervals

I have a code like that : library("survival") library("survminer") data("lung") res.cox <- coxph(Surv(time, status) ~ sex, data = lung) x<-confint(res.

Trying to replicate figures from Bayesian statistics without tears: A sampling-resampling perspective, but failed

I'm trying to replicate the three figures from the paper Bayesian statistics without tears: A sampling-resampling perspective, which can be fo

How to disable all Shiny UI elements, including a downloadButton

This answer explains how can one disable/enable all UI elements in a Shiny app. Among the two solutions given, the one I am interested in uses the shinyjs packa

Summary of descriptive data

i got a panel data set. I am analysing name changes of mutual funds. I created 6m prior & 6m past name-change Mean & Median values for various variables

How do I populate upper.tri of matrix with matched integers from the lower.tri?

Issue I have a dataframe of familial relationships coded with integers, where R01 is the relationship of person N to person 1, R02 their relationship to person

Calculate percent from total observations in r gtsummary::tbl_summary?

Issue: In gtsummary the tbl_summary function calculates column percent out of the total non-missing observations. I would like gtsummary to calculate percent fr

Get data from variable z where variable x = variable y

library(dplyr) df = data.frame(group_id = c(rep("a",5), rep("b",5)), prod_id = 1:10, prod_type = rep(c("a","a", "b", "c","d"),2)