Category "r"

R: Labels not displaying at a ggplot2 graph

Given this R script: library(glue) library(ggplot2) ir.data <- read.csv(file="~/apps/mine/cajueiro_weather_station/sensor_data/temperature_data.csv", header

how to fill missing in one column based on another in r

I have a subset of data frame as below. I want to fill the NAs in column "age at disease" so that the age of one individual with disease be same as the sibling

Turning code (instead of data) into a vector

I have the following code: install.packages("microbenchmark") install.packages("readxl") install.packages("data.table") I would like to create a vector of a va

Overwrite variables if condition is met, else keep existing values R

I have a data frame df<-data.frame(Name=c('H001', 'H002', 'H003', 'H004', 'H005', 'H006', 'H007', 'H008', 'H009', 'H010'),

Compute a function whose arguments stored in rows of a data frame in R

I have a very long function whose arguments take in different threshold values for different variables and give an event study result at the end. I want to comp

How to rank a variable in a column based on a conditional, when there are NAs in the column

I have a longitudinal data set with two people in which the rows of data are numbered as 'episodes', and some episodes have a test 'result'. The goal of the bel

Replace every sequence of letters with a random word

I created a list of random words: library(OpenRepGrid) list_of_words <- randomWords(100) list_of_words <- gsub("[^A-Za-z ]", "", list_of_words) list_of_wo

Drawing a visualization of system capacity (pipe flow?)

I need to reliably and repeatably visualize a system which is like pipes that can pass a certain amount of fluid per unit of time. The real system is a therapy

r - Plotting monthly time series data in R - cannot plot more than 10 series

I'm having a lot of trouble plotting my time series data in R Studio. My data is laid out as follows: tsf Time Series: Start = 1995 End = 2021 Frequency = 1

Fixed effect instrumental variable (IV) regression with available diagnostic tests

May I please know an R package and code to run fixed effect instrumental variable (IV) regression with available diagnostic tests (e.g., weak instrument test, e

Select xml files and their corresponding jpg files from a folder with R

I have have a folder with about 4000 jpg files and only about 50 of them have a corresponding xml file. I want to select those jpg files that have a correspondi

How to get the frequency( count) of Variable C when Variables A and B are mentioned together?

I have the following dplyr code: df3 <- Table3%>% group_by(Q6,Q9,Q11) %>% summarise(count = n()) %>% mutate(per = paste0(round(100 *count/sum(

R - Created package documented with roxygen2 is there a way to create a PDF of all the functions documentation? [duplicate]

As I explained in the question, I made an R package using devtools and roxygen2. When I type ?function the roxygen2 documentation displays in

Adjusted Survival Curves in R From Cox Model at Specific Covariate Values

I'd like to plot adjusted survival curves from a Cox model at specific covariate values. The survfit function in the survival package and ggsurvplot in survmine

Dplyr Lags on Summarised Grouped Data

Using dplyr, I'm looking to summarise a new column of data as a lagged version of an existing column of grouped data. Reprex: dateidx <- as.Date(c("2019-

Create and fill new columns based on range information from two other columns

I have the following data: df <- data.frame(group = c(1, 1, 1, 2, 2, 2), start = c(2, 2, 2, 7, 7, 7), stop = c(4, 7, 8,

Avoiding a Loop to Extract Vectors From Rows in Dataframe in R

I have data in a text file in which the cases are stacked in a single column. I need to extract selected lines from each case into vectors. I know how to do t

How to fix pandoc (error 1) in rmarkdown for html output?

I'm using pandoc version 2.18 and R version 4.1.3. I'm using rmarkdown to knit a document into an html format, but repeatedly receive the following error: pando

Subset rows of a table if they contain a specific character vector

I know this is a common question and I've read through many other stackoverflow entries but I am still stuck, apologies! I'm a beginner to R (still!). I have an

Reverse order of bar chart colours while keeping legend order and colours

I am working on ggplot2 in R, and have used automatic colouring for the plot. It plots stacked bar charts and then converts them to the pie chart. Here is the c