Most voted "r" questions
R is an open-source environment and programming language for statistical computing, bioinformatics, and graphics. It is advisable to supplement your question with a minimum reproducible example.
Learn more…2,359 questions
Sort by count of
-
4
votes2
answers88
viewsCreate a column with the second highest row value
I would like to create a column on dataframe teste with the second highest value of the respective line, as I did to find Min and Max. library("matrixStats") teste <-…
-
4
votes1
answer1129
viewsCalculate derivative and integrals in R
I have a set of functions that I need to calculate their respective derivatives and integrals. Because there are many I thought it best to create a function that takes an expression as an argument…
-
4
votes1
answer27
viewsCombinatorics and Probability
When I combine for example 4 strings ["A","B","C","D"] 2 to 2, ie AB,AC,AD,BC... I can count on how many occurrences A and B appeared? My problem involves 16 items that combined 4 to 4 generate…
rasked 3 years, 3 months ago Fernando Malheiros 41 -
4
votes3
answers2072
viewsHow to join two data.frames of different sizes per column in R?
Suppose I have two different date frames.: print(DADOS_1) linha coluna1 coluna2 1 1 3 2 3 4 3 1 1 4 2 2 print(DADOS_2) linha coluna3 coluna4 1 3 1 2 2 2 3 5 0 4 2 4 5 1 3 6 3 1 I need to unite…
rasked 5 years, 5 months ago Izak Mandrak 1,059 -
4
votes1
answer155
viewsBar graph ggplot in R
I would like to know how to remove these letters a that appear in the bar chart caption in ggplot in R. I want you to have the bar values the same way it appears in the image, but when I run the…
-
4
votes0
answers57
viewsEM algorithm error with while loop
Hello, my project needs the EM algorithm below, where are all the codes. The error is in the loop while, which is where the hope and maximization steps are. The error message is: "Error in while…
-
4
votes1
answer417
viewsHow to use auto.Rima to predict 24 periods or more in R?
I made a prediction using the auto.arima where my database is monthly values from Jan/2018 to Sep/2019. My training base is from Jan/2018 to Jun/2019: VL_TR_treino_5S = window(VL_TR_TS_5S,…
rasked 5 years, 1 month ago Izak Mandrak 1,059 -
4
votes2
answers89
viewsRearview Metacharacter x does not take the corresponding groups when I change the order of these
The rear-view metacharacter \x repeats something captured in some group () previous in regex. For example: library(stringr) a <- 'quero-quero' str_extract(string = a, pattern = regex(pattern =…
-
4
votes1
answer665
viewsHow does the metacharacter t work in a regex?
I have this variable: y <- c('stack overflow', 'user number 2', 'nova\nlinha', 'nova \n linha') And these functions with their results: library(tidyverse) With \n: str_detect(string = y,…
-
4
votes1
answer103
viewsAccess data.frame information in R
I’m trying to develop a recommendation system using the R language. Basically, the system is music recommendation collecting information from a file where there is a certain amount of users and for…
rasked 5 years ago Mateus Dias 93 -
4
votes1
answer183
viewsDifference between the metacharacters b and B
The metacharacters \b and \B sane anchors that marks the boundaries of a string (where it starts, ends, or both). Works by the ASCII standard, containing only [A-Za-z0-9_]. That is, only parts of…
-
4
votes2
answers826
viewsHow to define the number of clusters in the Kmeans algorithm in R?
I’m studying the grouping algorithm Kmeans, and as a database for my study, I’m using the iris. base = iris The algorithm itself I managed to use without problems: base2 = base[3:4] kmeans =…
-
4
votes1
answer49
viewsAverage by classes after excluding MIN and MAX
I found some similar questions, but none with the same problem I’m facing. I need to calculate the average by class, but before calculating each average, I would like to exclude the MAX and MIN…
-
4
votes1
answer363
viewsR - How to turn values into percentages using Data.table?
I own a data.table() with the columns Region, year and Quantity. The amount is in total value, I would like to make them in percentage per year. What do I have: Região ano Quantidade Norte 2017 252…
-
4
votes0
answers379
viewsHow to change document language in rmarkdown using latex?
I’m writing a document in Rmarkdown and using Latex for figures and tables. I need the titles of figures and tables in Portuguese, so I tried the following: Rmarkdown file: --- Output: pdf_document:…
-
4
votes2
answers59
viewsHow to gradually transform n number generation in normal distribution in R
I have developed a code to solve the image issue, which is to try to approximate the percentage of 68.2% numbers generated in the normal distribution that are between -1 and 1. Follow the code: x…
-
4
votes1
answer342
viewsBar graph with different colors in ggplot2
I have a bar graph in the R with percentage variation, I would like the negative percentage values to be red, as in this example: But my chart is getting this way: Code I am using:…
-
4
votes1
answer145
viewsHow to make forecast charts in R?
I have a model that makes predictions and would like to plot the observed series and then the predictions, according to this graph: I tried to use the geom_smooth along with the geom_line, but…
-
4
votes1
answer101
viewsRmarkdown - How to create a . pdf with a different name than . Rmd?
I created a script in . Rmd that will be played for different years. So I would like to be able to change the name of the generated . pdf. As it is: Report File.Rmd generates Report.pdf How I would…
-
4
votes3
answers291
viewsIn R, what is a Tibble?
What is a tibble? How she differs from a data.frame? The code below creates a data frame.. set.seed(123) df <- base::data.frame( id = 1:10, texto = letters[1:10], numero = rnorm(10) ) df #> id…
-
4
votes1
answer49
viewsggridges: peak heights proportional to quantities
Would anyone know if it’s possible, using the ggridges, make the heights proportional to the quantities? Follow the example: The problem is that the summit height of the first element, A624, with a…
-
4
votes1
answer130
views(Language R) How to make the axis of the graphs more detailed in ggplot2?
I would like to know how to add more numbers to my y axis, so that the bottom grid has more horizontal lines. Note that in my chart, the Y-axis only shows the markings every 500 units (0, 500, 1000…
-
4
votes1
answer63
viewsFunction to find complete word, but independent of position in string
I’m having trouble using the str_detect to capture part of a text. I need the str_detect take only the word "garlic", but regardless of her position in the string. Ex: "Brazilian garlic", "Brazilian…
-
4
votes1
answer77
viewsWebscraping - Site with choices
I have a more general question (although this site is more suitable for more specific things), and I would appreciate it if someone could help with some tips on where to start. It is possible to…
-
4
votes1
answer28
viewsCommand line correction R in ggplot2
I used the following code to generate the attached chart ggplot(dados,aes(x = Espécies, y = DNASat, size = Reads, fill=Espécies)) + scale_y_discrete(limits = positions) + geom_point(shape = 21) +…
-
4
votes1
answer31
viewsNo convergence of the estimates of the parameters of the Richards model in the "nls" package of r even with good kick start
I am estimating parameters of nonlinear regression models sigmoidais, only the Richards model returns the error: fator de passos 0.000488281 reduzido abaixo de 'minFactor' de 0.000976562 found the…
rasked 4 years, 4 months ago George Lucas 41 -
4
votes2
answers83
viewsReference one color column based on another
I have a dataset with several columns, but a specific column is reference for the colors of the chart, as I can reference this column in scale_fill_manua ggplot automatically? Obs. The same color…
-
4
votes1
answer101
viewsHow to globally save the output of a function in R?
I have trouble saving function output in R. In the following code, for example, I create an array representing a sudoku game: quantLinhas <- readline(prompt = 'insira o número de linhas do…
-
4
votes1
answer72
viewsHow to plot the factors (spp) of the metaMDS result using ggplot2, related to the collection sites in the original data frame?
Given the following data frame: dat<-data.frame( "sitio" = c("a", "a", "a",'a', "b", "b", "b", 'b', "c", "c", "c",'c'), "amostra"=c(rep(1,4),rep(2,4),rep(3,4)), "sp1"=c(1,3,3,2,4,2,1,5,3,6,1,5),…
-
4
votes3
answers71
viewsConditional column based on multiple dplyr lines
I have this df: structure(list(id = c("R054", "R054", "R054", "R054", "R054", "GT68U", "GT68U", "GT68U", "GT68U", "GT68U", "G001", "G001", "G001", "G001"), car1 = c("sim", "sim", "sim", "sim",…
-
4
votes1
answer96
viewsOverlay two scatter charts into one (with ggplot)
I have 2 data frames for males and another for females (the variables are the same, crc and maxilla). From each of these df generated two charts. Now I’m trying to combine them into just one chart,…
-
4
votes1
answer82
viewsWhat are the differences between Rmarkdown and Rnotebook?
The RMarkdown has become a very popular interface and file type in recent years. I believe this is due to the fact that it allows using a single software to write complete statistical analysis…
-
4
votes1
answer30
viewsError while integrating a real function
I’m trying to integrate, under the whole line, the function: integrand_1<-function(x){ exp(-x/phi-y*exp(-x)/(phi*2)-(x+sigma2/2)^2/(2*sigma2))} Using the following data: df <-…
-
4
votes1
answer85
viewsScatter plot in ggplot2
Talks guys I’m wanting to create a scatter chart in R using the ggplot2, a scatter plot with gene size (lengthbp) X variants (frameshift, splice_acceptor, splice_donor, stop_gained), the figure…
-
4
votes1
answer72
viewsHow to transpose from "wide" to "long" (wide to long) with several variables?
I have a dataframe with multiple variables, as in the example below: df <- read.table(header=TRUE, text=" ID COR TIPO SITUACAO_2016 SITUACAO_2017 SITUACAO_2018 SITUACAO_2019 SITUACAO_2020…
-
4
votes1
answer113
viewsLine segments leaving the interior of a map of brazil using package ggrepel
I am trying to reproduce the format of the map below, however, I have been facing some problems to insert these "straights" on the map. After a search, I found the package ggrepel that brings with…
-
4
votes2
answers101
viewsInsert scale on y-axis for geom_line
I want to plot the columns analise1, analise2, analise3 in a single chart of lines but with different scales, because the width of the column analise1 is much larger than the other two columns. On…
-
3
votes1
answer5683
viewsHow to run a R script from the Windows command line?
I have a test file. A in the folder: C: Users Documents R And I’ve already added R to the windows PATH: C: Program Files R R-3.0.2 bin When in the cmd I try the command R CMD teste.R Windows does…
-
3
votes1
answer168
viewsHow to vary parameters of an equation?
For an equation of the type y = ax + b, we have two values for a and two to b, That is, we have four different equations. We already have a code that returns us the values of x and y for each…
-
3
votes2
answers412
viewsConnecting dots to the 3d regression line
This is the 3d version of this other question. Consider the following data: Income2<-structure(list(X = 1:30, Education = c(21.5862068965517, 18.2758620689655, 12.0689655172414, 17.0344827586207,…
-
3
votes1
answer1401
viewsUsing function to make a subset and plot with only 1 command (R)
My dataframe calls EWMA_SD252 3561 Obs. of 102 variables (daily volatilities of 100 shares since 2000), follows a sample : Data IBOV ABEV3 AEDU3 ALLL3 3000 2012-02-09 16.88756 15.00696 33.46089…
-
3
votes1
answer489
viewsGLM with random factor in R
I need to do a glm in R, but there is dependency between the data. I was asked to insert this dependency as a random factor in the analysis. But I’m not getting a command for it. Panorama: - GLM,…
-
3
votes1
answer60
viewsHow to know the fonts supported by commonality.cloud?
I would like to know which fonts are supported either by wordcloud or commonality.cloud. I imported some fonts with the package below but many of them don’t work. install.packages("extrafont")…
-
3
votes3
answers1031
viewsReplace Zero and Infinity values in a matrix (R)
In the example matrix below (daily stock returns) : IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.03981646 -0.027412907 -0.051282051 -0.05208333 -0.047300526 -0.059805285 [2,] -0.03000415 -0.030534351…
-
3
votes1
answer3385
viewsReplace specified column values in a matrix (R)
At the head office (ret_matriz) IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.040630825 -0.027795652 -0.052643733 -0.053488685 -0.048455772 -0.061668282 [2,] -0.030463489 -0.031010237 0 -0.040229625…
-
3
votes2
answers2857
viewsCompare 2 Matrices and Return a Third (R)
The following matrices being Matrix(A) [,1] [,2] [,3] [,4] [,5] [1,] 0.228 0.285 0.285 0.285 0.380 [2,] 0.228 0.285 0.570 0.380 0.228 [3,] 0.380 0.285 0.228 0.380 0.285 [4,] 0.285 0.285 0.570 0.380…
-
3
votes4
answers16549
viewsHow to include columns in a data.frame?
Consider the following data.frame: df <- data.frame(x=c("a","b"), y=c(1,2)) How to include a new column, say, z = c(1,2)?
rasked 10 years, 2 months ago Carlos Cinelli 16,826 -
3
votes2
answers886
viewsHow to perform a cross-tabulation and weighted?
I would like to do a cross-tabulation but with the prop.table I cannot use the weight variable. I use the command below: prop.table(table(mydata$Q_15,mydata$Q_35),1)…
-
3
votes2
answers314
viewsPresentations (slidify and Rpres) with Latin characters (ç, ã, é...) corrupted
I am preparing slides in R, but the Latin characters (ç, ã, é etc...) get corrupted when the presentation is compiled. I tried both with slidify and with Rpre, same problem. Someone knows how to…
rasked 10 years, 2 months ago LucasMation 411 -
3
votes1
answer278
viewsI get NA when I convert Character to time (Posixlt)
Why do I get NA when I do this conversion from Character to Posixlt? library(bReeze) data(winddata) tempo <- winddata[,1] tempo[1:6] # Preview # [1] "06.05.2009 11:20" "06.05.2009 11:30"…