Category "r"

R create sf polyline from nested list of coordinates

I have a nested list of coordinates in the following format: feature <- list(type = "Feature", properties = list(`_leaflet_id` = 125L, feature_type = "p

Sending Queries to a table in RMySQL, using R variables

I am trying to write data I have created in R and stored in arrays to MySQL table. Currently this is how I am doing it, for(z in 1:60){ dbSendQuery( mydb,

Replace_na with map function

penguins %>% map(~replace_na(list(.=0))) Why the code above didnt work to replace na in the dataset penguins? The result is below # A tibble: 8 x 1 .

How can I change global fonts in officer

I am trying to make a word document from R. I use the officer package. doc = docx(title = 'test') When I do this, the standard template is used. Is there a w

Clustering longitudinal data with multiple variables in R

I have a dataset that contains the observations of 30 people and each of them had done 20 experiments. Suppose my data looks like this: ID trial reaction r

How to vectorise ifelse function in R?

I am trying to make a vectorized function using ifelse in R, but my code is only taking the first element of the vector. For example, as shown in my code below

How to use MatchIT R package to use caliper width on logit of the propensity score instead of the propensity score?

The R package MatchIT uses a caliper width on the standard deviation of the propensity score. Is there a way to use logit of the propensity score?

XGBoost object 'trainD' not found

I was running this code on RStudio param <- list(colsample_bytree = 1, subsample = .6, booster = "gbtree", max_dept

Fill dataframe with missing data in R

I have a code that counts how many points there are for each quadrant of 10x10 and shows the result in each quadrant I have this Dataframe qx qy n

r add math symbol to x axis text

I am trying to add a math symbol (sum) to some texts in x-axis. For example, if this is my plot. data(iris) p1 <- ggplot(iris, aes(x=Species, y=Sepal.Length)

How to Determine the K^th character in the concatenated string

Given a list that contains N strings of lowercase English alphabets. Any number of contiguous strings can be found together to form a new string. The grouping f

Mean columns with almost the same name

I have a data frame containing only one row with named columns. The data frame looks somewhat like this: poms_tat1 poms_tat2 poms_tat3 tens1 tens2

Fast matrix determinant calculation with specific structure

I have a k*k squared matrix with diagonal elements x>0 and all other elements y>0. The values of k, x, y are all subject to change. Now I need the determi

Saving patchwork ggplots with furrr future map only saves one of the plots

I am trying to save a list of patchworked ggplots (ie ggplots that have been wrapped together into 1 plot using the package patchwork). My real data is creating

R markdown not knitting because of parse raw had been removed

I've been having problems on knitting Rmarkdown, and it's been frustrating that I have no idea what to do. Every time I knit them, it always ended up with an er

error in command "installed.packages" in R language

This command: installed.packages(c("ggplot2","swirl","lattice","car","fimport","tseries")) generates the error "Package LibPath Version Priority Depends Im

more VARBINARY columns in result set fo SQL Server R sript

In my R script for MS SQL Server I try to return one column VARBINARY() and one VARCHAR(). However, server allow only one column when VARBINARY is returned: T

Plot customised vertical lines up to the curve

I want the vertical lines to not go beyond the curve line after they intersect Example data: x <- 1:50 dat <- data.frame(x = x, y = 1 - exp(-x/43)^4) ggp

How to swap x-axis tick labels with plus/minus signs table

I'm struggling to figure how to change my x-axis label in ggplot2 from regular identifications to not-so-regular plus/minus signs to relate the addition or abse

Suppress messages in console when running shiny

See example: shinyFunction <- function(){ shinyApp( ui = basicPage( actionButton('print_message', "Print a message") ), server = fun