Collect all kinds of r programming exceptions and fault solutions.

permutation test on throwing three dice with sides labelled in a binary way

I want to model throwing three, six-sided dice permuted n number of times (say 6,000 times), where each die has three sides labelled 1 and 0.
I want to test whether three dice getting either all 1s...

Trying to Plot Standard Normal Distribution and t-distribution on same graph

dat <- data.frame(dens = c(rnorm(1000000), rt(1000000, 4)), lines = rep(c("a", "b"), each = 100000))
ggplot(dat, aes(x = dens, fill = lines)) + geom_density(alpha = 0.5)
This is my code. I'm tr...

Shiny app does not work and seems to not read the server side code at all

I am fairly new to R (using R Studio) and am looking to build a shiny app as a user interface for my homemade trading platform. I can see the menu, tabs etc. of the app but none of the action buttons

Which is the bigger population using t.test in R? How to tell to the function?

I have a question about using t.test to check if the population mean is bigger than another.
Imagine I have 2 variables in a dataframe d:
Weight: Numerical variable (weight of people).

How is air_time calculated in flights data set of nycflights13 package R

I am analysing the flights dataset of the nycflights13 package in R.
I have an issue understanding how exactly the air_time is calculated.
My code to view the data, starting with the shortest f...

Solving system of 4 equations in 4 unknowns using R

I am trying to solve the following 4 equations in 4 unknowns using R:
m_1 = 1 + p_{11}m_1 + p_{12}m_2 + p_{13} m_3 + p_{14} m_4,
m_2 = 1 + p_{21}m_1 + p_{22}m_2 + p_{23} m_3 + p_{24} m_4,
m_3 = 1 +...

aws- update R version

I need to install some packages that require R>=3.5. I am in a bash console of a SageMaker instance.
sh-4.2$ sudo yum --disablerepo="*" --enablerepo "epel" list available | grep "R-core"

How to download data from website by selecting right inputs using R (the query does not change the URL)

I am new to web scraping. I would like to pull out data from this website:
I have managed to get a response using the GET() function (even though not pos...

Give group ID for date periods

I'm trying to automatize the attribution of a group number by periods of time. Because I'm writing of function to aggregate time series of weather data by different time periods defined by the user...

r - read zip file from s3 using r

Is it possible to read a zipped sas file (or any kind or file) from s3 using r?
Here is what I'm trying:
s3read_using(FUN = read_sas(unzip(.)),

Error trying to connect to a droplet in analogsea

The initial attempt was to use analogsea to create a droplet using do_provision, but it seems that the problem is that I just can't seem to get ssh working. I'm not sure if something is wrong with ...

add_attachment in blastula R package

How can I sent an attachment in blastula.
correo <- compose_email(
body = md("Tarea_01"))
correo %>% add_attachment(file = "emilia/tarea_01/liquenes.csv", filename = "liquenes")
correo %...

How do I aggregate data for glm() function in R

I am trying to estimate relativities for insurance pricing using a glm. I'm using the "freMPTL" in CASdatasets. ClaimNb is my response, Exposure is my Exposure, I'm interested in ClaimNb/Exposure.

How does R recognize which column is the unique identifier in my dataset?

I am fairly new to R and having trouble with my unique identifiers of participants.
I imported my dataset from Stata into R, all good. All variables appear as they should including my ID variable.

Read selected CSV files in R

Read a few CSV files(say 100) from a folder having 1000 of them using the name of CSV files.
I used
list.files(pattern = "*.csv")
to list all files.
Then, I need to read-only selected f...

Is there a way to merge lists of regression summaries in R?

I have simulated log-gamma data of various sizes and 'shapes', and then fit a gamma and lognormal model to these simulated data.
Here is my relevant code:
gm_glog <- function(size.i, alpha.i) {

Column split within a dataframe into multiple columns and cbind within the same dataframe

I have a dataframe containing "ID" columns.
I want to split the columns named "ID1", "ID2" etc into multiple columns (image attached) such that the characters before and after "/" symbol are in sep...

Error: Input files not all in same directory, please supply explicit wd

After trying to build a PDF that worked ~2 weeks ago, no fuss, on a new machine with a fresh install of R, R studio, bookdown, etc, I have this error:
Error: Input files not all in same directory, ...

Why doesn't the Legend title change?

I have a melted dataframe. It's name "melted_data".
Tr variable value
1 3.00 J48 0.3500
2 3.25 J48 0.6300
3 3.50 J48 0.4820
4 3.75 J48 0.4210
5 4....

UTF-8 support in R on Windows

Since new function 'Beta: Use Unicode UTF-8 for worldwide language support' is added on Windows10, I thought it is possible for R to convert locale environment to UTF-8. However, when I try to change

Isn't this function for grid.arrange correct?

grid.arrange(hist1, hist2, nrow = 2)
This is the line of code with error
The error shown is -------------------------------------
Error in grid.arrange(hist1, hist2, nrow = 2) :
could not find

Create a dynamically rendered UI in shiny with reactive input data

I want to be able to have UI inputs in shiny that update themselves based on the previous choices of a user. So in the example below, the intended behavior would be that the user chooses from cyl, ...

Count common sets of items between different customers

I have data on customers and the different products they have purchased:
Customer Product
1 A
1 B
1 C
2 D
2 E
2 F

SEM PLS on R - plspm does not install

I need to run SEM (with PLS) analysis, and was provided script that is used the plspm package.
I tried to install but it says it's no longer available for current R update.
Warning in install.packa...

How can I add an extra symbol in legend of a ggplot graph?

I want to add a symbol to the legend of the ggplot graph. Symbolic code of the ggplot is represented below, my question is, how can I draw that (*) symbol circled in the picture?
library(ggplot2 )

Using ggpairs to get correlation values

I used ggpairs to get the following plots:
I want to know which pair has the largest absolute correlation. However, how am I supposed to ascertain this when some of the pairs, such as Power-Span, ...

Clustering extremely large dataset in R (DBSCAN)

I have a very large dataset (200M observations) with spatial points around the world with a ground resolution of 30m. I would like to assign clusters based on a minimum of 33 points per cluster and a

R highcharter x-axis date issue

I have a data frame contains month-end data. I'm using the stacked column chart but have an issue with the x-axis date labels. For example, it shows April under the March column.

Error in plot(grafo) : object 'grafo' not found

I'm recently learning how to use R. Im really new at this and this is the first question that I'm posting here. Back to the point, I got an error in this formula (object not found) but I cannot fin...

Knit PDF from Rmarkdown with one image per page, vertically centered

I have hundreds of images that I would like to knit to a single pdf file from Rmarkdown. I would like only one image per page, and for each image to be horizontally and vertically centered on the p...

Unable to use phangorn::phyDat

I am following an example from ‘Analysis of Phylogenetics Second Edition and Evolution with R’ from Emmanuel Paradis.
He is doing:
I am doing pretty much the same:
x=c('garras','garras','garras', '

Adding a new column on a data frame depending on another dataframe with a different size

I have two data frame in R.
The first one is as follows:
Species; Camera; Records
Species A; Cam A; 3
Species B; Cam A; 1
Species A; Cam B; 2
Species B;Cam B; 8
and the second is as such:
Camera; ...

R read an URL table with a free text column

I would like to read a txt table inside an URL. The table does have 3 columns; the second column is a character column with few words in it with quotations around words. The data cannot be accessib...

I need to extract Excel sheets by name from a list of data frames in which each row is the name of the sheet

So, I have a lot of files in xlsx, and I need a few sheets from each file. The structure is something like this:
3 sheets with final grades, like a report card. the first one is global score, the s...

Using RLE in a function in R

I have the following data:
dat2<-structure(list(year = c(1979L, 1979L, 1979L, 1979L, 1979L,
1979L,1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L,
1979L, 1979L, 1979L, 1979L, ...

Apriori model not showing obvious associations

I am doing Apriori model for the first time. I have created a test dataset as attached. Clearly there are strong associations like {A,C} -> {K}, {A,C,G} -> {K} etc. But the Apriori model give...

How can I speed up my R code when multiplying across tables?

Here is an example of what I am trying to do.
dtA <- data.table(A = 1:3, B = 4:6, D = 7:9)
dtB <- data.table(id = c("A", "B", "C", "D"), multi = c(0.1,...

Spatial panel model in R (spml): error with balanced spatial panel data

I looked at many posts on similar issue but didn't find a solution for my case.
I have balanced panel data for the CBSAs in the US from 2005-2015, when I ran fixed effects model with the following

R: Spread Time Series Data Based on Event Time

I have a large time series dataset that currently iterates through the data to change the time series data into events divided by time interval. I am looking for something more slick than iterating

Frequency Table of Categorical Variables as a Data Frame in R

I would like to create a frequency Table of all Categorical Variables as a Data Frame in R. I would like to find the frequency and percentage of each survey response (grouped by condition, as well ...

YouTube API only fetching latest 20,000 videos on a channel

I'm trying to get the videoId's of all the videos in a channel.
But when I run the command list_channel_videos(channel_id = "channel_id", max_results = 5000) using package tuber in R, onl...

adding horizontal "separating" lines in a single boxplot in Base R plotting

I need to add a "separating" line in Base R boxplot to separate difference groups. In the example below, I want to separate groups A and B (each having 2 levels) using a horizontal line (...

R: Monte Carlo simulation by Permute or Sample to shuffle cluster labels to test enrichment

From this data set, I have all patient samples (69 rows total) assigned by my cluster analysis and was labelled as column 3 "Cluster.assigned", 8 clusters in total, UNEQUAL size per clust...

error in load () funtion when try to laod .RData format

I need to convert a shapefile (.shp) formate into .RData format. I used the following codes but when I load the RData format file I get error
# to save .RData format which runs smoothly with...

R linear model regression line fitting

I'm trying to fit a linear model. If I do this in excel, I get a sloped line (rather than horizontal which I get from R) and an r squared value of 0.125.
Clearly the correlation is weak, but I'm not

Split comma-separated strings in a column into separate rows

I have a data frame, like so:
data.frame(director = c("Aaron Blaise,Bob Walker", "Akira Kurosawa",
"Alan J. Pakula", "Alan Parker", "Alejandro Amenabar", "Alejandro Gonzalez

How remove columns with same values (dplyr::select)?

I have a data:
df <- data.frame(
x = c('col', NA, 1),
y = c('s', NA, 3),
w = c(0, 0, 0),
z = c(NA_character_, NA_character_, NA_character_)
x y w z
1 col s 0 <NA&...

How to create multiple sub-directories and change the directory in loop to export the plots in respective directory in R?

There multiple conditions and I want to get the plots for the all the combinations of the conditions as presented bellow. I could create plots for various combinations of provided conditions, with

How do we ensure that the datatable will automatically update itself after we execute an update query after clicking a button

Good day all,
I am planning to make my datatable automatically update itself after an update query is executed (by pressing the respective button). So what happen now is the following:
The user will

Colour the most expensive and least expensive observations in R

So I have a hourly price series with 168 observations and my goal was to plot them in a chart, where on the x-axis the hours are numbered from 1-168 and on the y-axis the prices. My problem is I wa...