Category "r"

Is there a way to vectorize seq() and grep() to use on conjunction with dplyr?

Apologies if this is obvious, I don't have much experience with R. I have a function contains_leap_year(date1, date2) that I want to pass in as a condition to d

Prevent .libPaths() in R from resolving symlinks

I have two almost identical systems. I install software in system1 (a remote testing environment) in /export/apps/ and then rsync the files to system2 in its /

Custom interaction Plotly in ggplot - R

I have a massive dataset that makes graph plotting tedious and complex. Assume this simplified dataset: library(data.table) library(plotly) library(ggplot2) lib

R: create diagonal from 1 to 10 in matrix -> returns only last value

I need to modify a matrix filled with random numbers so that the resulting matrix has a diagonal with the numbers 1 to 10 and everywhere else there are supposed

Different output when running lmer and summarise

I am doing some easy linear mixed effects model as below: lmer( as.numeric(o.m_20_r_coded)~ site + (1 | village), o.m_20_r_coded_dat) %>% summary() Random

Create several new variables using a vector of names and a vector for computation within dplyr::mutate

I'd like to create several new columns. They should take their names from one vector and they should be computed by taking one column in the data and dividing i

Facing error with terraform code for importing multiple runbook to azure automation account

I have created the azure automation account using terraform code. I have multiple runbooks PowerShell scripts saved in my local. I am using for.each option to i

Merging three dfs of different row lengths

I need to merge three separate DFs ("factors_sed", "resp", and "npoc_sed") based on the shared column "Samples". Each DF contains a different number of rows (s

How to do a new data frame of the latest value reported in each column?

I've got a table like this: country continent date n_case Ex TD TC -----------------------------------------------------

r behaves strangely copying eigenvectors to a matrix in a for i loop

I'm a bit confused. A matrix A has 8 eigenvalues, some of them are complex, some are real. I want to copy only the eigenvectors that correspond to the real eige

grouped (twice) and stacked bar chart with facet wrapping

Here is my sample data mydata = data.frame (student =c("A","A","A","A","A","A","A","A","A", "A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","B","B",

Issues on importing multiple files

I am new to R. Currently I have spent hours on Youtube videos looking to import a folder of CSV files for my data analytics project. The following are my codes:

need to plot multiple spatial maps side-by-side in a single window using sf plot function in R

I like to plot all my 5 spatial maps of drought indices in a single window using sf plot function in R. I am able to plot all maps seperately but unable to plot

Annotate ggplot2 across multiple facets

I have recently started using the facet_nested function from the ggh4x package and I really like the look of the nested axis. I would like to annotate the plot

Errors loading GeoJSON exported from R's sf package into Mapbox Studio

I am trying to learn how to use Mapbox Studio, but I can't figure out how to upload GeoJSON files that I export from R's sf package using the st_write() functio

Change values in multiple columns if condition is met (R) [duplicate]

I have a dataframe: n <- 50 df <- data.frame(id = seq (1:n), age = sample(c(20:90), n, rep = TRUE), s

Predict on test data, using plm package in R, and calculate RMSE for test data

I built a model, using plm package. The sample dataset is here. I am trying to predict on test data and calculate metrics. # Import package library(plm) library

How do I group a list of numbers based on fixed recurrance

I have a list: x <- c("1", "2", "2", "3", "3", "3", "2", "2", "3", "3", "3","2", "2", "2", "2") What I need to do is make them shortened like this. 1 2 3 2

Correct way to create a software install script which can manage dependencies

I'm currently working on an university research related software which uses statistical models in it in order to process some calculations around Item Response

Matching values in different datasets by groups in R

I have the following two datasets: df1 <- data.frame( "group" = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5), "numbers" = c(55, 75, 60, 55, 75, 60, 5