# 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.

294,679 questions

**0**

votes

**0**answers

6 views

### R Network Graph with mult-line labels?

I am trying to create a network graph of nodes with labels that contain multiple lines. The lines should have different font size and style to convey information about that node. The details must be ...

**0**

votes

**0**answers

6 views

### Exporting multiple imputed objects with MICE

I am imputing my missing data using mice. The problem here is that it takes an hour or two to get the imputation done. So as it finishes imputing, I would like to export it for future use so that I ...

**0**

votes

**0**answers

10 views

### How reduce the noise of a image?

I am loading text from some images. With some of them, I am having problems, with this type of image
library(magick)
library(tesseract)
image_read(fichero.jpg) %>%
tesseract::ocr(engine = ...

**0**

votes

**0**answers

4 views

### beamer rmarkdown presentation unable to knit pdf file instead knit html document that too is not knitted

I have a beamer rmarkdown file for preparing PDF presentation as teaching material. However, when I click knit with pdf, the output is displayed in html document, instead of beamer_presentation (pdf). ...

**0**

votes

**0**answers

15 views

### Ascending count within each group in a dataframe [duplicate]

For a dataframe with groups, like so:
df <- data.frame(group = c(rep("A", 5), rep("B", 3), rep("C", 4)))
group
1 A
2 A
3 A
4 A
5 A
6 B
7 B
8 B
9 C
...

**0**

votes

**2**answers

18 views

### dynamic column names seem to work when := is used but not when = is used in data.table

Using this dummy dataset
setDT(mtcars_copy<-copy(mtcars))
new_col<- "sum_carb" # for dynamic column referencing
Why does Case 1 work but not Case 2?
# Case 1 - Works fine
mtcars_copy[,eval(...

**1**

vote

**1**answer

15 views

### Changing datastructure to create correct bar graph in ggplot

I would like to make a graph in R, which I managed to make in excel. It is a bargraph with species on the x-axis and the log number of observations on the y-axis. My current data structure in R is not ...

**1**

vote

**1**answer

21 views

### subtract the different dimensional arrays in R

Let A and B be arrays, of dimension [2,3,4] and [100,2], respectively. Note that 2 is the common dimension.
My desired answer is an array C of dimension [100,2,3,4] such that
C[h,i,j,k] = A[i,j,k] -...

**2**

votes

**2**answers

30 views

### Wide data frame with 4 columns to long data frame with 3 columns

I have a data frame (sample below), as follows:
df = structure(list(Stage1yBefore = c("3.1", "1", "4", "2", "NA"),
Stage2yBefore = c("NA", "2", "3.2", "2", "NA"), ClinicalActivity1yBefore =
c(TRUE, ...

**0**

votes

**0**answers

17 views

### p.adjust function in R gives unexpected value of 1 for all raw p-values

I am trying to adjust my raw p-values using the Bonferroni method. However, all the adjusted p-values show values of 1. I don't expect this. I have run this function many a times previously. I also ...

**0**

votes

**1**answer

23 views

### Calling a variable from a data frame, the name of which is stored as character

So basically I'm using a For loop, that loops between names that are stored in a vector(partners) and returns a the names as data frames containing specific data. The code goes something like this
...

**-4**

votes

**2**answers

27 views

### Second Modest Value

DataSet
pincode Time
12345 10
12345 10
12345 10
12345 9
12345 9
23456 7
23456 7
23456 5
Expected Output
Pincode Time
12345 10
12345 9
23456 ...

**0**

votes

**1**answer

21 views

### Plotting multiple graphs from a list

I have a time series data from 1990 to 1994 of 5 variables in 15 sheets. I read all these data to a list. I need to do a time series plot of all the 5 Variables for 15 companies in multiple graphs. ...

**-1**

votes

**0**answers

12 views

### labelling grouped bars in geom_bar

I want to add labels to individual bars in a set of grouped bars using geom_bar
sit3 is the data.frame
sit4.long <- melt (sit3)
ggplot(sit4.long, aes(Type, value, fill=variable)) + geom_bar(stat="...

**0**

votes

**1**answer

28 views

### Splitting list of n element into one dataframe of n vectors

I have a list which contains say r of 5 elements of unequal length
r
$First
[1] "Jan" "feb" "March" "Ram"
$Second
[1] "Jan" "feb" "April"
$Third
[1] "Jan" "feb" "May" "Shyam"
$...

**0**

votes

**0**answers

8 views

### Error in if (ncol(x) == 1L) { : argument is of length zero [duplicate]

I am trying to create a panel dataset with following data:
my data looks like this
country GDP_2012 GDP_2013 GDP_2014 Exports_2012 Exports_2013 Exports_2014
A 50 150 160 ...

**0**

votes

**2**answers

26 views

### Is there any method to combine data frames properly?

I have a problem with combining data frames which share the same rows. I imported rasters from different folders and converted them into data frames and tried to combine them together but the data don'...

**0**

votes

**0**answers

9 views

### How to fix “The metric ”Accuracy“ was not in the result set. AUC will be used instead”

I am trying to run a logistic regression on a classification problem
the dependent variable "SUBSCRIBEDYN" is a factor with 2 levels ("Yes" and "No")
train.control <- trainControl(method = "...

**0**

votes

**0**answers

15 views

### Formatting scale with a categorical Variable in a GGPlot?

I am new to R and struggling to do a basic ggplot!
I am trying to plot the number of employed (y-axis) for each constituency (X-axis). Because there are 632 constituencies this is causing some ...

**0**

votes

**0**answers

11 views

### Minute.steps parameter unused argument error for timeTinput

I have trying to put a step of 15 minutes on my timeInput for a shiny app but the argument minute.steps is not recognised. Is there anything I am doing wrong?
library(shiny)
library(shinyTime)
ui &...

**0**

votes

**0**answers

11 views

### how can i solve this Error in plot.svm() missing formula in R

i am trying to plotting svm but every time i get this error
"Error in plot.svm(Linearclassifier, training_set) : missing formula.
Calls: SVM_Function -> plot -> plot.svm"
Linearclassifier = svm(...

**0**

votes

**1**answer

12 views

### Replicate XL GRG Nonlinear solver in R (example provided)

I am trying to replicate with R this optimization problem for which the XL solver seems to do the job (I am assuming it's a decent one); I seem to fail getting the package/function ticking all the ...

**0**

votes

**1**answer

16 views

### R package googlesheets default browser change

When I run
#get the library
library(googlesheets)
#initialize token
gs_auth(new_user = TRUE)
it always opens my firebox browser, however, I want it to open my chrome browser, is there a way to ...

**1**

vote

**0**answers

15 views

### R: error in tableplot: Error in if (by < 1) stop(“'by' must be > 0”)

I'm a beginner in R and cannot understand what's the problem in that simple code:
install.packages("tabplot")
library("tabplot")
library("MASS")
Boston$chas <- factor(Boston$chas)
Boston$rad <-...

**0**

votes

**1**answer

27 views

### Remove NA in 3D array and reshape

I have an array num [1:800, 1:533, 1:3]. Essentially an image with 800 columns, 533 rows and 3 channels. In every row of every channel, there is exactly one NA.
How can I remove all NA's in all ...

**0**

votes

**0**answers

13 views

### Repeated two way anova in r

I would like to do a two way repeated anova in r. My data includes three species (A, B, C) subjected to three treatments (1,2,3) - there were 3 replicates of each treatment. Class data (1-5) on each ...

**0**

votes

**0**answers

14 views

### Processing while uploading files in R shiny

I have several file inputs in an R shiny application that feed info to create different datatables (different tabs).
When I click in any of the buttons to perform operations, the file inputs that ...

**1**

vote

**2**answers

32 views

### How to add a matrix to a data.frame?

below is some dummy data.
Suppose I have a dataframe
df = data.frame(source = c("X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10",
"X11", "X12", "X13", "X14", "X15",...

**-1**

votes

**0**answers

16 views

### K clustering in R not returning expected values

My clustering script is not returning the results I want, and I am trying to figure out why exactly that is, or if there is a different code command I should be using. I am trying to do a k means ...

**0**

votes

**1**answer

22 views

### having the error message “number of items to replace is not a multiple of replacement length”

I get the error message "Error in dist.mat[j, i] <- d :
number of items to replace is not a multiple of replacement length" when I run the script:
uncenter.distance <- function(X) {
n &...

**1**

vote

**0**answers

36 views

### How to download this data using R/Python

I was trying to download data from below link:
Link
Below is my R code-
library(XML)
library(RCurl)
readHTMLTable(getURL("https://www.nseindia.com/products/dynaContent/common/productsSymbolMapping....

**0**

votes

**0**answers

13 views

### How to automate data labels [duplicate]

I need to automate data labels on my bar graph.
H <- c(0, 1, 4, 0, 17) # Create the data for the chart, cont3.#
M <- c("Very Low", "Low", "Medium", "High", "Very High")
barplot(H, col =c("...

**0**

votes

**2**answers

28 views

### Looping read.xlsx for reading in multiple sheets and saving them as separate DF´s

I want to read in sheets 3:8 of my excel file and save them separately.
I got something like this:
for (y in 2012:2017){
save("Year" ,y)<- for (i in 3:8)
{
read_xlsx("/Users/.../Desktop/...

**0**

votes

**0**answers

31 views

### R fast way to read values from a matrix?

I wish to read values as fast as possible from a matrix (or a vector).
The standard way would be as follows:
# defining the matrix
x = matrix(runif(100), nrow=10)
# reading one value
x[2,3]
I have ...

**0**

votes

**1**answer

21 views

### Convert repeating values in a column into NA

I would like to convert repeating values in a vector into NA's, such that I keep the position of the first occurrence of each new value.
I can find lots of posts on how to solve the removal of ...

**1**

vote

**2**answers

19 views

### combine rows in r, summing values and concatenating characters; combining factor levels

I want to combine two or more rows, such that the numeric values for variables (v1..5) are summed and the character values, which are factor levels are combined like this:
v1 v2 v3 v4 v5 fa fb fc
...

**0**

votes

**0**answers

3 views

### Ugarchforecast Error: “ugarchforecast-->error: n.roll must not be greater than out.sample!”

So i did a gjrGauch regression
spec<-ugarchspec(variance.model = list(model="gjrGARCH"),mean.model = list(armaOrder=c(0,0)))
fit<-ugarchfit(spec,data = FF4F$WML)
and want to do a forecast ...

**1**

vote

**2**answers

23 views

### How to get geom_point size to reflect actual values rather than relative values

There is probably a simple solution to this, but I'm too much of a newcomer to know what it is - so I'd greatly appreciate any help.
I'm trying to create a graph that will show the average time to ...

**0**

votes

**0**answers

10 views

### error in MFA not convenient group definition

I'm trying to run MFA on a dataset of 23 columns. The first eleven are categorical, and the last twelve are continuous. I keep getting the error message "not convenient group definition"
I've made ...

**0**

votes

**1**answer

15 views

### sum of one column (with same name) in all data frames in a list

How can I sum one specific column in all data frames in a list an put them in a new data frame?
An small example is:
A <- data.frame(matrix( nrow = 2, ncol = 2))
B <- data.frame(matrix( nrow = ...

**1**

vote

**1**answer

27 views

### dplyr filter to get only the values that one of the groups take

I would like to filter to get the rows from any group of my tibble, where one of the variable matches the values taken by one of the groups.
structure(list(type = c("A", "A", "A", "A", "B", "B", "B", ...

**0**

votes

**1**answer

24 views

### How do I write this complicated formula in R Markdown?

I have been trying for days to figure out how to write this formula in R markdown...
...but I didn't find anything on the web.
Can you help me please?
Thanks.

**1**

vote

**1**answer

20 views

### R: retrieve dataframe name from another dataframe

I have a dataframe dataselect that tells me what dataframe to use for each case of an analysis (let's call this the relevant dataframe).
The case is assigned dynamically, and therefore which ...

**0**

votes

**1**answer

20 views

### data aggregation and invalid data type message?

I have been stuck on how to aggregate some date for a while.
DF2 <- aggregate(.~fund, cbind(DF["fund"], test[assets_cols]), sum)
I am receiving the following error message,
Error in model....

**0**

votes

**0**answers

9 views

### How can I make 2 clustering column in heatmap?

I would like to draw heatmap.
On the other hand, I want to make a clustering only with binary (case vs. control; status = 0 /1) not like the result attached.
What should I do?
Many thanks advanced.
...

**1**

vote

**1**answer

19 views

### Prevent R abbreviating single string output in console?

If I run
Sys.getenv(c("R_HOME"))
I see
[1] "C:/PROGRA~1/R/R-36~1.0"
Which is an abbreviation of the full path.
How can I return the full string (in this case, the full path)?

**0**

votes

**0**answers

4 views

### How to use here() for paths to css, before_body and after_body?

I have a collection of RMarkdown documents which are distributed over a hierarchy of folders. All of the documents refer to the same CSS and header/footer files. I have the paths to these files hard-...

**1**

vote

**0**answers

5 views

### How can I plot multiple control limits in an EWMA control chart with qcc?

I can plot an EWMA control chart with 3 sigma limits (nsigmas=3). Can anyone help me with plotting additional control lines on the same chart such as 1 and 2 sigma limits?
The only way I can think is ...

**0**

votes

**0**answers

8 views

### How to simulate a pedigree using simul.pedigree with different number (but fixed) of sire and dam in R

I'm new with R and I want to simulate a livestock pedigree of 5 generations. I'm using simul.pedigree in synbreed package to set up a pedigree. I successfully make a random mating pedigree of 5 ...

**0**

votes

**1**answer

18 views

### Error with if statement when runnin R in jupyter

I am running the following if conditin in R without any problem:
nrow<-ifelse(S1_input, 1, ifelse(S2_input & nchar(bands)>40, 2, ifelse(S1_S2_input & nchar(bands)>40, 3, ifelse (...