Category "r"

Install R packages through "Jobs" tab in Rstudio

In Rstudio, I usually install R packages using the console by install.packages('pkg-name') command. However, when some R packages are required in an R script, R

What is the solution to Error during conditional logistic regression in R?

set<-c(1,1,1,2,2,2) gender<-c(1,0,1,0,1,0) smoke<-c(1,1,0,0, 1,0) case_control<-c(1,0,0,1,0,0) data<-data.frame(set, gender, smoke, case_c

if() statement with paste0() or grep() in r

I made reproducible minimal example, but my real data is really huge ac_1 <-c(0.1, 0.3, 0.03, 0.03) ac_2 <-c(0.2, 0.4, 0.1, 0.008) ac_3 <-c(0.8, 0.043

R stops responding when trying to plot

When trying to draw any plot R just stops responding. plot(1:10) The result is not responding. I am using MacBook M1 pro. It was working perfectly. Just sudden

possible to have separate factor levels for each axis in one graph?

I'm trying to plot a Sankey diagram of financial flows between a source country and counterpart country. ggplot(dat_ggforce, aes(x=x, id=id, split = y, value=yv

convert df into a pairwise distance matrix

I'm using code (not my own) that converts a data frame (Mol.Info) of mass spec peaks and associated elemental ratios into a pairwise distance matrix between mas

How should you package non-R library dependencies?

I am writing an R package which requires a binary file that I have wrapped for use with R code (using system2). To work, the binary file requires a .dylib depen

compute SD and VAR for a time variable

How I am trying to compute SD and VAR for a difference in start and end times, its a time-variable basically, I get a NA when I run: hms::as_hms(var(hms::as_hm

Add unique horizontal line for levels in facet_grid

I want to add a unique horizontal line across each row of a set of facet grid boxplots. x<-c("species_X","species_X","species_X", "species_Y","species_Y",

How to add sequence of numbers to each group of a data.frame?

I have a dataframe of US zipcodes and I want to add a sequence of numbers to each unique zipcode while repeating the rest of the rows. Right now, my data looks

Does the caret package for R properly implement repeated CV when passed a multifold object to trainControl's index option?

I'm hoping the answer to this question is a quick "yes" or "no" but I cannot find it explicitly in the caret documentation or elsewhere online. I want to perfor

Changing values in a raster

I have a raster file (created in QGIS, from a vectorial file). I would like to know if it is possible, in R: 1) to change the values of the pixels? (I believ

Find closest datapoint to a date in another dataframe

I have two data frames. One data frame is called Measurements and has 500 rows. The columns are PatientID, Value and M_Date. The other data frame is called Pati

Finding the turning point (inflection point) of COVID-19 infections using inflection package

I am not sure if I have done my inflection point calculation correctly. Based on lab confirmed cumulative case data in the epicenter of the current epidemic, we

What does the %||% operator do in R? Percent Pipe Pipe Percent

I came across this code when reviewing the R plotly library: modify_list <- function(x, y, ...) { modifyList(x %||% list(), y %||% list(), ...) } What d

How do I remove Japanese characters?

I have some data with Japanese characters from survey data. Some of the survey questions and answers (multiple choice) are given in both English and Japanese, e

Sliding window algorithm to analyze values of fasta segments

I have two segments of a random fasta file 1 Segment1 AAGGTTCC 2 Segment2 CCTTGGAA I have another random data set containing dinucleotides' energy values as A

Finding increases from 'baseline' in the graph, not sure how to do

I want to write an algorithm that spits out the points highlighted by arrows. I've tried using a second derivative but it returns a similar plot to the one ab

How to replace a value with NA across an entire dataframe

Is there any way to replace all the "-95" that can possibly exist in a dataframe with NA across all the columns?

Extract time (HMS) from lubridate date time object?

I have the following datetime: t <- "2018-05-01 23:02:50 UTC" I want to split it to time and date. When I apply date(t) I get the date part. But when