Category "r"

Fill in missing variables of family relationship matrix

I have a dataframe of family relationships (parent, child, spouse, etc.) which is partially filled as per example below. I am trying to use R to fill in the mis

How do I deal with special characters like \^$.?*|+()[{ in my regex?

I want to match a regular expression special character, \^$.?*|+()[{. I tried: x <- "a[b" grepl("[", x) ## Error: invalid regular expression '[', reason 'M

How to subset text from a word docx AFTER a matching phrase

I would like to subset text from an original word docx ("original.docx") into a new word docx ("desired.docx"), AFTER the match of the phrase "Drop Text Before

Merging sheets (2) from multiple excel workbooks in one while using information from sheet (1)

I have 200 workbooks (1 per subject) with two sheets each. I was able to merge all sheets 1 and all sheets 2 in two separate data frames using the following scr

R : How loop a function creating named dataframes according to dataframes contained in a list passed in argument?

I made a function that takes a dataframe as argument, and creates two dataframes in output according to a threshold value of one of the columns. These 2 output

R Objects not in global environment in VS Code

I am trying to use VS Code to run R. When I open R terminal in VS Code, I cannot find R icon on the left most column. I created a .r file, loaded that into VS

R 4.2.0: write.table() "clipboard-1024" copies only columns name

I used write.table(mat, "clipboard-1024", sep="\t", row.names=FALSE) to copy from R to Excel in previous versions. After updating to 4.2.0 it copies columns nam

How do I pass arguments to srvyr inside of a function?

so I'm using srvyr to calculate survey means of a variable (y) from a survey object, grouping by a categorical variable (x) from that same survey object, and th

How to check if values in first dataframe are contained or match values in another dataframe

I am using R to work with some dataframes. My issue is related on how to check if values in a variable in a first dataframe match with values in another datafra

Getting data from another column from a row where a different variable matches

Minimal working example: library(dplyr) df = data.frame(group_id = c("G1","G1", rep("G2",8)), prod_id = c(1,2,5,6,7,8,9,10,11,12),

how can I use if condition inside the loop in r

I defined a function creates 3 random numbers from 1 to 36, and I allowed repetition. I want to test how many times I can get three same numbers in one hand in

Shiny Error: replacement has 2 rows, data has 1

I am trying to create a Shiny app, in which users can select an "option" in the drop-down box(created using selectInput) and Shiny will display the data table a

gganimate does not work properly in combination with geom_area

I would like to animate a ggplot with gganimate using geom_area with different values for the years between 2000 and 2050. However, for some reason if I include

R: T-statistics with subsets

I would like to have a table as ouptut where I have the t-statistics between the difference in means of certain variables and based on two specific subsets of m

Constant warning message with reshape::melt in r

I am constantly getting warning message like : as.is should be specified by the caller using true Code is like : difficulty_data <- data_original[,c(-1)] %

Trouble reading HTML table saved with gtsave

I saved a table created by gt in HTML using gtsave. I'm having trouble loading and displaying this small HTML table in Shiny The HTML table is at: https://filed

Error in R using imputed data : Error in `[<-.data.frame`(`*tmp*`, j, value = c() replacement has 165 rows, data has 163

I am trying to add a column in an imputed dataset (I used mice). I managed to transform the imputed dataset in a dataframe, add the column that comes from anoth

When validating cox model: NaN when using rms::validate, Divergence or singularity in [all] samples

I would like to fit a Cox model for prediction of 1-year survival using a specific set of predictors. The data contains 78 events in 620 subjects. I don't think

Simultaneously remove the first and last rows of a data frame until reaching a row that does not have an NA

I have a dataframe that contains NA values, and I want to remove some rows that have an NA (i.e., not complete cases). However, I only want to remove rows at th

could not find function "symbolicInt"

I simply cannot get these functions: symbolicInt and integral. Not sure why. I just re-installed everthing. I thought maybe it was becuase of the libraries but