Category "r"

Getting Visual Studio Code to (auto-)format R-Code

Working on Windows 10, no Formatter for the R-Language seems to do its job in Visual Studio Code. I've tried R support for Visual Studio Code and R-Tools, which

Automating conditional logic for database data checks in R

I am trying to do a large data check for a database. Some fields in the database are hidden, so when I am doing the datacheck, I need to ignore all hidden field

Error: cannot allocate vector of size X Gb Rstudio

Never had this problem before but now it's constantly there for any piece of code I write. > sessionInfo() R version 4.0.2 (2020-06-22) Platform: x86_64-w64-

R: Display "popup" information when mouse hovers over (graph) visnetwork

I simulated some data and created a graph network in R using visnetwork: library(igraph) library(dplyr) library(visNetwork) #create file from which to sample f

RStudio install packages from Azure DevOps

I'm creating some internal packages with R in RStudio. My repositories are hosted in Azure DevOps. I saw the renv.lock and there is a section for repositories.

How to left_join() two datasets but only select specific columns from one of the datasets?

Here are two datasets: (this is fake data) library(tidyverse) myfruit <- tibble(fruit_name = c("apple", "pear", "banana", "cherry"), number

spatial panel regression in R: non conformable spatial weights?

I am trying to run a spatial panel regression in R with the splm package. So I have polygons with summarized data over time and I want to see how the dependent

clustering standard errors within MLMs/lme4

Is it possible to use both cluster standard errors and multilevel models together and how does one implement this in R? In my set up I am running a conjoint exp

mapview and plot show different output for the same rasterLayer, why?

Below is the rasterLayer RASTER_slope in a plot (4 NAs are shown in white): Here is the metadata of RASTER_slope class : RasterLayer dimensions : 4, 4, 1

stargazer2 - automatically return odds ratio

I am doing a logistic regression and was recommended the stargazer2 function instead of stargazer function since it would automatically convert log odds to odds

Using purrr::possibly to catch dynamic error messages

I've written a custom function that does a number of checks and throws a different error when a check fails. Below is a simple example function that takes a dat

How to make data frame into raster object R

I have a data frame with one column of values. How do I make this into a raster image with the following parameters? I would also like to save it as a .tif rast

Create a vector using rep() and seq()

How to create a vector sequence of: 2 3 4 5 6 7 8 3 4 5 6 7 8 4 5 6 7 8 5 6 7 8 6 7 8 7 8 I tried to use: 2:8+rep(0:6,each=6) but the result is: 2 3 4 5

How to look at differences between 2 columns in R

I just need to write some code that will look at the difference between the "est_age" and "known_age" columns in my data set. Then I need to know what percenta

max.col with the value not the index

If I have a matrix: mod_xgb_softprob$pred[1:3,1:3] [,1] [,2] [,3] [1,] 6.781361e-04 6.781361e-04 6.781422e-04 [2,] 2.022457e-07 2.

quarto rmarkdown code block to only display certain lines

I have a .qmd / .rmd file that wants to show the output of block of code. The code block has a lot of lines at the beginning that I'd like to hide, in the examp

In dplyr using str_detect and case_when in R

This is my df: mydf <- structure(list(Action = c("Passes accurate", "Passes accurate", "Passes accurate", "Passes accurate", "Lost balls", "Lost balls (in o

How to avoid gaps due to missing values in matplot in R?

I have a function that uses matplot to plot some data. Data structure is like this: test = data.frame(x = 1:10, a = 1:10, b = 11:20) matplot(test[,-1]) matlin

change in the structure of table

I was required a function which can give the required result below, transpose of the current output table. i want variables in rows and and row variables in col

Error Installing flipMaxDiff package from github

Relative newby here struggling with an older install for R. Trying to get flipMaxDiff from either of the remaining github repositories (Displayr doesn't provide