# Questions tagged [r]

R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization, and general computing. Please provide minimal and reproducible example(s) along with the desired output. Use `dput()` for data and specify all non-base packages with `library()` calls. Do not embed pictures for data or code, use indented code blocks instead. For statistics related questions, use https://stats.stackexchange.com.

319,295
questions

**0**

votes

**0**answers

6 views

### Analyzing and Visualization of School data of 10th Standard of whole Nepal in R programming

For one my project, I need to analyze and visualize a data of a Country that contains the data of all the school over the country based on Geographical region, Development region, Zone and district on ...

**0**

votes

**0**answers

5 views

### Is there a way for HTML output from r package flextable to have a vertical scrollbar if the table is long?

I am creating HTML output from a dynamic table in R using flextable as follows:
output$tbl <- renderUI({
DF %>%
flextable() %>%
autofit() %>%
theme_booktabs() %>%...

**0**

votes

**0**answers

6 views

### In HMM, how to extract probability (not delta probability) of observation being generated by each state and calculate expected value

I'm trying to get the probability of the last observation being generated by each state. But the posterior function seems to give "delta probability".
With the probability and transition matrix, can ...

**0**

votes

**0**answers

8 views

### R install_github: Error: Failed to install 'unknown package'

I'm new to GitHub and I'm stumped. I can't get install_github to work.
I followed the helpful instructions here to set up my account: https://kbroman.org/github_tutorial/pages/init.html.
I have an ...

**1**

vote

**1**answer

19 views

### selecting the top n elements from a row and taking their mean

I have a data that represents assets returns. I want to select top N assets from each row and calculate mean of return of that selected assets. In detail,I want to make a function that would select ...

**0**

votes

**2**answers

16 views

### Applying a function to each element of a group in R data frame

I am trying to find the first non-NA element of column w in each group and then construct a new variable which starts from the index of that non-NA element and follows this law of motion:
k_{it+1}=k_{...

**0**

votes

**0**answers

12 views

### Removing rows of character strings that are subsets of a larger character string

I'm using the below codes to create association rules for a project;
RawData_Kicks_Rules <- apriori(RawData_Kicks_ALLKICKS, parameter = list(supp = 0.005, conf = 0.5, minlen=3, maxlen=9))
...

**0**

votes

**0**answers

12 views

### using group_by with filtered inputs in shiny for map

I have what may be a complicated question. I'm trying to build a filterable map with shiny. I'm using the selectizeGroupUI feature because it allows you to easily filter inputs in a way that links all ...

**0**

votes

**0**answers

10 views

### manipulating glue-generated title on my gganimate

I have created a basketball animation using gganimate, as seen below. You can get the full animation on my blog post (Look at animation under "Paul Pierce Isolation").
NBA Animation
Now, there is ...

**0**

votes

**2**answers

27 views

### How to filter greatest value for each hour in a data frame? [duplicate]

Essentially, I want to create a bar graph that's a sum of all rainfall each year. Readings are recorded about every hour, but sometimes there are multiple readings per hour. Unfortunately, when there ...

**0**

votes

**0**answers

11 views

### twListToDf function not found in TwitteR Package (R)

I would like to enquire why my program couldn't work as I have manually installed the twitteR package.
library(twitteR)
setup_twitter_oauth(api_key, api_secret, access_token, access_secret)
...

**-2**

votes

**0**answers

24 views

### Approximating a statistical calculation

First, what on earth is going on inside this code block?
run7=c()
for (i in 1:1e4) {
run1 = sum(runif(14) > 0.7)
run7 = c(run7, run1 < 4)
}
run9 = sum(run7) / length(run7)
Second, how ...

**1**

vote

**0**answers

10 views

### How to make different font sizes on graphs with specific point sizes

I'm trying to get specific font sizes for scatterplots based of Nature guidelines. I'm told to keep all my point sizes for text at 7 so I've used par(ps = 7). However, I need a different font size for ...

**0**

votes

**0**answers

15 views

### for loop transferring to foreach in R language

I am trying to find a connection between for loop and foreach function, but all the examples are so basic that I am lost in my huge loop. Can someone help me to understand how to make it?
I have ...

**4**

votes

**0**answers

21 views

### ggplot - geom_segment() with mutiple arrows

I am working on Principal Component Analysis (PCA).
I found ggfortify works great but would like to do some manual adjustments.
Here then trying to plot the PCA results as below:
evec <- read....

**0**

votes

**0**answers

11 views

### Where is the definition of R_NilValue/What is the guarantee on the returned value of TYPEOF(R_NilValue)?

I want to be able to determine whether an input to a .Called C function should be NULL. To do this I need to know if the R parameter is the R equivalent. R uses R_NilValue as a sentinel for the null ...

**1**

vote

**0**answers

7 views

### Shiny App Disconnected From Server When Selecting an Input and Popups Not Working

I have created this shiny app:
https://garrettrsmith.shinyapps.io/RIB_shinyapp/
When I run it locally I can switch between the years in the SelectInput drop-down menu no problem. When I deploy the ...

**0**

votes

**0**answers

13 views

### Sending R Markdown output as body email via outlook (RDCOMclient) - R version 3.6.1

I use this exact code (Sending R Markdown output as body email via outlook (RDCOMclient)) and it worked just fine, until I update my version of R to 3.6.1.
I also tried the 3.5 version of ...

**0**

votes

**0**answers

7 views

### How do I get my shinyApp to read in my data file?

I have my server.R, ui.R and csv file all in my github repo. When I run my shinyapp from R using
shiny::runGitHub("st558projectfinal","cgcomora")
I get an error that object 'crimes' can't be found....

**0**

votes

**1**answer

24 views

### Combine multiple csv files (similar column) in one with selective row and column in r

I have around 300-500 CSV files with some character information at the beginning and two-column as numeric data. I want to make one data.frame with all the numeric values in Such a way that I have ...

**-3**

votes

**0**answers

10 views

### how can i plot in the frequency for multi variant in rstudi?

I have a small dataset like what attached.
i want to plot their frequency in a way that in my x axis I have chr(which stands for chromosom) next to each other for "SMC" 80 and in y axis show thier ...

**-1**

votes

**1**answer

18 views

### Expanding the summary table in r

Good day,
I've got a table with 15000 rows of data with 5 variable columns. I'm using the summary function in R and I get the following output:
enter image description here
Which is fine, however, ...

**0**

votes

**1**answer

26 views

### How to create a dataframe in R with a column calculation that references its own value in the prior row?

I am try to use R to calculate sales as a function of inventory as a function of sales. See below data snapshot. Is there anyway to calculate this?
Group, Day and Build are independent variables
...

**0**

votes

**0**answers

14 views

### Source a bunch of files in R script in a nice way

I have a script, let say main.R. I have a dozen of function files that I source in the main script.
It looks like:
source('doThis.R')
source('doThat.R')
source('coolFun.R')
source('anotherFun.R')
.....

**0**

votes

**1**answer

23 views

### Grouping by with multipolygon geometry with sf (using R)

I have a custom shapefile I put together. It works fine when I plot it all at once. But I'd like to group by certain variables to plot specific shaped regions. For example:
+-------------+--------+---...

**1**

vote

**1**answer

15 views

### How to force R to auto-update column classes/types?

I'm reading a data file into an R data.frame where it's pretty much guaranteed that R will get the wrong class/data type because of a specific (annoying) row that's included in the file. Ironically, ...

**0**

votes

**1**answer

18 views

### R: Formattable -Column Will Not Update Based Upon Condition

I run this code to produce the formatted table and I get no error but the condition I have set in place appears to not be working at all. I It looks right? What I am trying to do is for 'mAge' column ...

**0**

votes

**0**answers

17 views

### Is there an efficient way to add a percent sign to every number in a set of data in R? [duplicate]

I'm currently adding labels to a plot using a dataframe of percentages that I've calculated from a set of data. The dataframe is 15 numbers long, and I would like for the final dataframe to have a ...

**0**

votes

**1**answer

31 views

### Crazy looping over lists and split dataframes, while sending emails. 90% there.. need the final push

I have a project dataframe
dummy <- data.frame("lead" = c("Sammy", "Dan", "Lawrence", "Sammy", "Dan", "Lawrence", "Lawrence", "Sammy"),
"project" = c("project4", "project2", "project3", ...

**-1**

votes

**1**answer

23 views

### Order function in R cannot be reversed with - or rev() when column has alpha and numeric characters

First time I ever cared to sort because I need to report this in a specific way. Typically, smallest to largest sort in excel on column quarter returns YTD, 3,2,1. etc. However, I cannot sort using ...

**1**

vote

**0**answers

20 views

### Error in stat_smooth when plotting power regression with select points

I am trying to plot a power regression line in the formula y ~ a*x^b using ggplot in R.
It looks like I need to use the method = "nls" under stat_smooth but am getting a warning message that missing ...

**0**

votes

**0**answers

5 views

### Using cattonum to en/decode categorial data in R for prediction

I'm using R package "cattonum" to encode (leave one out) a column in a dataset:
df_sample <- catto_loo(df_sample, response = target_col, ... = c("Colors", "KindOfSweets"))
The column gets ...

**0**

votes

**0**answers

10 views

### R_ContinueUnwind not found in R.dll

While attempting to test a modification a stan program in Rstudio using rstan Rstudio crashed several times. I then attempted to run a simpler program that I know runs just fine as a test. This ...

**-2**

votes

**1**answer

34 views

### R: Replace NA with date value. If date value exists in both columns choose the earliest date

I am working with two data frames and have merged them thanks to the advice on other StackOverflow threads. Now I'm struggling to get the values from one column into the other column IF they meet ...

**0**

votes

**0**answers

10 views

### Can't display x and y labels, when plotting with the quantreg command

I'm trying to plot the result of the quantreg command, but the labels of the graph don't show up. I'm running this code:
plot(summary(qrg), parm="agua_esgoto", xlab = "Quantiles", ylab = "Piped water ...

**0**

votes

**1**answer

18 views

### Is there a way to merge grey scale images (JPEG) in R to create 'RGB' channels?

Hi I was wondering if it was possible to convert a single greyscale (JPG) image and convert them to 3 RGB channels on Rstudio.
Additionally, I have 3 different greyscale images that I want to merge ...

**0**

votes

**0**answers

22 views

### Trouble with basic regression loops in R [duplicate]

I'm trying run a linear model of the effect of year on the natural log (number of measles cases +1) from 194 different countries individually so that I can gain the slope from the linear model from ...

**1**

vote

**3**answers

39 views

### Understanding why sapply in R returns vector of longer length

I am parsing through individual lines of code in R to get a better understanding of a large function. While I know sapply apples a function over a vector, I am having trouble understanding what it is ...

**0**

votes

**0**answers

43 views

### Separate/Group plain text with Regex and PHP

I can separate data from the plain text below with Regex.
Plain text:
190.A 42-year-old male patient has been delivered to a hospital in a grave condition with dyspnea, cough with expectoration of ...

**3**

votes

**3**answers

33 views

### How to call columns implicitly in certain R functions

There are some functions in R where you have to call columns explicitly by name, such as pmin. My question is how to get around this, preferably using tidyverse.
Here's some sample data.
library(...

**1**

vote

**1**answer

39 views

### What's the fastest alternative in R to do this string regex processing?

I'm dealing with 75GB XML files i.e. it's therefore impossible to load them in memory and build a DOM XML tree. Therefore I resort to processing chunks of lines (using readr::read_lines_chunked) in ...

**0**

votes

**0**answers

21 views

### how to plot non-standard contour plots in R (or Matlab)

I would like to plot in R following contour plots representing two dimensional cumulative distributon functions (CDF)
A CDF in 2 or more dimensions is not unique (Lopes et al. The two-dimensional ...

**0**

votes

**1**answer

38 views

### Is there a way to reorder the y axis values in decreasing order while keeping the x axis values the same in R?

I have a set of numeric data that corresponds with specific dates and I would like to make a line chart showing the changes. When I enter my code, I end up with a graph that is not ordered on the y ...

**0**

votes

**1**answer

36 views

### How can I concatenate one row to the previous row in a data frame, if a condition is met?

I am an intermediate user of R and have a data set of ~850,000 rows that was edited through Stata, saved as a csv, but about .01% of the rows got split to the following row after column 4. Column 5 ...

**0**

votes

**1**answer

25 views

### Using existing lines as geom_ribbon() min and max

So I have three lines that I'm charting. The upper and lower lines are the confidence interval, so I'd like to use geom_ribbon() to fill in the area between the lines with color. But I haven't been ...

**0**

votes

**0**answers

6 views

### Updated Data pull with R Script to Power BI but now I'm getting “DataFormat.Error: CLOSXP”?

I'm trying to troubleshoot data that I query through Power BI but keep getting this error, DataFormat.Error: CLOSXP. Is there any troubleshooting ways to find out what the CLOSXP means?

**0**

votes

**0**answers

14 views

### Programming transition matrix for chess pieces

Situation
I am currently trying to program the transition matrix for the king in the game of chess. We know that, on a 8x8 board, the probability of the king reaching a space j from a space i, where ...

**0**

votes

**2**answers

18 views

### Barplot with given data

The data frame below is called median.price
postcode medianprice
1 NG1 1127.0
2 NG2 900.0
3 NG3 975.0
4 NG4 750.0
5 NG5 650.0
6 NG6 ...

**0**

votes

**1**answer

27 views

### How do I filter multiple rows with matching column values based on all rows meeting a certain condition? [R]

I have a data table called iso:
> iso
variant_id transcript_id is_NL counts nrows
1: chr10_129450960_T_C_b38 chr10_129467297_129536240 0 33029 458
...

**0**

votes

**0**answers

18 views

### Legend with un-plotted variable in ggplot2

I have data where each point lays on a spectrum between two centroids. I have generated a color for each point by specifying a color for each centroid, then setting the color of each point as a ...