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
-
3
votes3
answers309
viewsHow to replace variables with NEGATIVE values with their ABSOLUTE VALUE within a date.frame in R?
First of all, what is an Absolute Value? We can say that the Absolute Value or Module is the same as the distance from a real number to zero, because the module of a real number arose from the need…
-
3
votes1
answer101
viewsBootstrap in linear regression model - Calculating the importance of variables
I’m calculating the importance of variables for multiple regression with function varImp package caret. But when doing hair using function and bootstrap I cannot recover the values as I got for R².…
-
3
votes4
answers101
viewsDealing with dates of heterogeneous formats in R
I have 236 files in . csv that have all the same columns. My goal is to join them all into one data frame only. However, each of them has 4 columns with date and time values. The problem is in the…
-
3
votes2
answers74
viewsSelect dataframe information based on specific conditions
I am working with election data for mayors in Brazil and would like to select in my database only data related to municipalities based on two conditions: Municipalities where the dispute took place…
-
3
votes0
answers250
viewsSums and Dynamic table by R
I need to do a calculation in Rstudio that is at first simple to do in excel. We have a table with two columns, one with occupation codes (Occupation Column), and another column with two codes for…
-
3
votes1
answer167
viewsHow to partially disregard NA in R operations with a historical data series?
I have a set of rain data measured every hour and I need to add this data throughout the day. For this, I am using the commands below: library(dplyr) df %>% group_by(data) %>%…
-
3
votes1
answer155
viewsStandardize bar width between distinct graphs ggplot2
Hello, I would like to know how I can standardize the width of my bars from ggplot2 between distinct charts. I would like to leave the bars of all charts at the same width. For example, I have these…
-
3
votes1
answer438
viewsHow to increase Y-axis scale marks in graphics in ggplot2?
I have a chart with very long scale marks between you, I’d like to increase the amount, but I don’t know how it’s possible. I would like to increase the number of values in the Y axis, for example,…
-
3
votes2
answers129
viewsLoop Operation with Multiple Data Frames
Assuming the following example in R: Sample_data <- data.table(code = c("AAPL","AAPL","AAPL", "AMZN","AMZN","AMZN", "MSFT","MSFT", "GOOG","GOOG","GOOG", "FB"), date =…
-
3
votes1
answer72
viewsProblem with key in ggplot, using double axis y
I would like a help to solve this problem. I would like the caption to present dotted lines (linetype), dotted (shape) and colors (colour) equal to the graph, but this graph has a double axis for y,…
-
3
votes3
answers1427
viewsMoving average in R
I need to make a simple 7-day moving average on R, I’m using the function rollmean package zoo, but the values being returned are incorrect. Example: library(zoo) teste <- sample(1:50) mean <-…
rasked 4 years, 6 months ago Alexandre Sanches 1,223 -
3
votes1
answer50
viewsWhat does the "~" operator mean in tidyverse context?
Suppose the data set below: df_1 <- structure(list(var_1 = c(42.0324095338583, 86.828490421176, 42.4499513395131, 87.8373390808702, 69.4962524808943), var_2 = c(52.6775231584907,…
-
3
votes1
answer69
viewsHow to put currency prefix (R$) in the status bar of the shinyWidgets R package?
Is there any way to show the numbers as currency (R$), including thousands and cents separator, in the progress bars of Shiny’s shinyWidgets package? I’m trying to run some code, but they all…
-
3
votes2
answers294
viewsHow to plot distinct regression models using the ggplot2 + ggpmisc or gridExtra packages?
Hello! I have some difficulty generating graphs with different regression models (quadratic, linear) (FIGURE 1), it is observed that the graphics are loose ("free" scales) when using the…
-
3
votes2
answers72
viewsHow to turn a column with a sentence per row into a column where each row is a word of these phrases?
I have the following structure: structure(list(frases = c("agricultura pecuária e serviços relacionados", "produção de lavouras temporárias", "cultivo de cereais", "cultivo de arroz", "cultivo de…
-
3
votes0
answers45
viewsProblems with split captions in ggplot2
Hello, I’d like your help on subtitles using the ggplot2. I want to extract a caption to use in another graphic that uses plot_grid, but I don’t know why, but the same code works (Figure 1) and…
-
3
votes1
answer42
viewsNotice message by adding year, month and day with the ymd() function of the lubridate
I’m practicing with the pack hflights I install the package; I load the package; and I carry the lubridate install.packages("hflights") library(hflights) library(lubridate) The data (Year, Month,…
-
3
votes1
answer73
viewsHow to place the values of the discrete Y scale in ascending order?
I want to create a histogram in ggplot but the y-axis values are getting out of order. I want to place them in ascending order on the axis. I tried to use the "reorder" function but it didn’t work.…
-
3
votes1
answer78
viewsHow do I distribute the content of a column to other columns in R?
I’m trying to distribute the contents of one column in another 3 columns. I have the following Data Frame: library(tidyr) df<-data.frame(Coluna= c('2237-5953', '(RE) PENSANDO DIREITO', 'B4',…
-
3
votes1
answer107
viewsWhat is the difference between facet_wrap() and facet_grid() in ggplot?
The options facet_wrap() and facet_grid() in the ggplot have similar purposes, produce graphs with results stratified by a categorical variable. However, sometimes these options produce…
-
3
votes1
answer60
viewsHow do I create a list to save countless Numbers generated by my function in R?
Good evening dear friends! I created a script that generates several age pyramids simultaneously. In this case, the great advantage is to generate hundreds, or even thousands of pyramids in a few…
-
3
votes1
answer72
viewsYAML: How to use the current date in the Rmarkdown compilation?
How to automatically include the current system date in the title of the document to be compiled by R-markdown? When I try to include the system date in the field date through the YAML code: r…
-
3
votes1
answer41
viewsGrid on R does not work
Hello, I’m trying to create a chart with the following code: boxplot(covid_DF$obitosNovos ~ month(covid_DF$data), main="Média de obitos novos por mês no Distrito Federal", xlab="Mês",…
-
3
votes1
answer50
viewsCreate R column from the number of records by 2 Ids
I am starting in R and stackflow. I ask for your help. I have the following dataframe: library(lubridate) ID = c("000225", "000225", "000225", "000225", "000226", "000226", "000227", "000227",…
rasked 4 years ago Bruno Fernandes 43 -
3
votes1
answer29
viewsHow to remove duplicate figures generated by the geom_errorbar function?
How do I remove the other tags generated by the function geom_errorbar()? I only need the marking that is circled in the image. Database dataset = structure(list(structure(c(1L, 1L, 1L, 1L, 1L, 1L,…
-
3
votes1
answer60
viewsGeom_rect does not recognize alpha
I have a chart made with geom_rect, the problem is I’m using the argument alpha and he’s not applying the transparency on the chart. My code: dados %>% mutate(median_x = inicio + floor((fim -…
-
3
votes1
answer35
viewsHow to check the periodicity of a series in the R?
I have a database with 5182 series and I need to check if these are daily, monthly or quarterly. Doing this job manually would take a lot of time, so my question is: It is possible to check whether…
-
3
votes2
answers118
viewsLogarithmic scale - Histogram R
I plotted a chart of type histogram, using the following code: hist(dados1$Prec, breaks=40 , col=rgb(0.2,0.8,0.5,0.5) , border=F , main="" , xlab="Precipitação (mm)", xlim=c(0,140), ylim =…
-
3
votes1
answer30
viewsGraph error with package ggplot2 and function sumarySE
I seek your assistance in solving some problems in constructing a graph with average and standard error in R with the ggplot2 package and summarySE function. In my work I evaluate the effect of…
-
3
votes1
answer52
viewsApply row-to-row formula within a table in R
I have a table where I need to apply a row-to-row formula to multiple columns, and the formula is: row value - mean(all column values) / standard deviation(all column values) is a normalization of…
-
3
votes4
answers285
viewsSeparate data by values on the line?
In the lines of my dataframe I have an identifier with letters for each observation set. Some of the observations have more than one letter, in which case these observations are actions together of…
-
3
votes1
answer85
viewsColoring a map with differing color intensity in ggplot2
I’m trying to create the Plot of a color map of Brazil with a specific color, the "#2D3E50". However, using this color on the map to color from the smallest area (light shade) to the largest area…
-
3
votes2
answers35
viewsError to calculate pBias
I need to calculate the pBias, but it’s a mistake. I’ve performed this calculation before and it worked, I don’t know what could be going wrong, below the code I used: #observado obs <-…
-
3
votes1
answer73
viewsggplot2: get color palette used in scale_color
Do you know if it is possible to get the color palette used in scale_color_*? I would like to get the specific colors (Hex color codes) used with the package paletteer in each case to then use it in…
-
3
votes1
answer36
viewsProblem with dots that don’t join lines in ggplot
I have the following data file Go for data reading structure(list(ano = c(2018L, 2018L, 2018L, 2018L, 2019L, 2019L, 2019L, 2019L, 2020L, 2020L, 2020L, 2020L), Regiao = c("BaixadaFluminense",…
-
3
votes1
answer47
viewsggplot: geom_area - error with aes(Fill)
I have the following data and would like to create a chart with the ggplot2::geom_area() with different colors for the positive and negative values. However, I am getting an error and I am not being…
-
3
votes1
answer56
viewsHow to calculate average between lines
I have a dataset of information with years on the line. I need to do an average every two years, as the example below, where the first four columns are the existing data and the last two, which is…
rasked 3 years, 8 months ago Daniel Manzi 51 -
3
votes1
answer45
viewsAutomatically creating new variables through interaction between two pre-existing variables
Suppose I own the following set of dados: dados #> letras numeros cores valor #> 1 a 1 branco 2 #> 2 a 1 preto 1 #> 3 a 2 branco 9 #> 4 a 2 preto 4 #> 5 a 3 branco 8 #> 6 a 3…
-
3
votes2
answers56
viewsApply a function to a dataframe R
I created a function to automatically check if the value of a column is contained in a list. I could do dplyr::mutate + dplyr::ifelse, but as they are for many columns, it would be a very long code.…
-
3
votes1
answer39
viewsHow to delete several elements from a list() at once in R?
I have the following list: x <- list("1", 1, 2, 2.1, TRUE, "yes", "necessary", 31, FALSE, "FALSE") would like to exclude from it all the elements which NAY are whole numbers and not characters,…
-
3
votes1
answer55
viewsHow to change values on the y-axis
How do I change the values of the y-axis to 0,5,10,15,20? # Dados da produção da aquicultura 2013-2019 producao_aquicultura = structure(list(Valor = c(19350491, 22082777, 21063695, 20828670,…
-
3
votes2
answers35
viewsHow to select rows that have text searching in all columns of a data frame
I want to select only the lines that have the text "Try", similar to grep in Linux. Follow the example: my.data <- data.frame( A = c("prot trypsina catalic", "7", "123", NA, "1419", "ab", "ab",…
-
3
votes2
answers28
viewsCommand to create multiple columns in a data.frame conditioned to other 2 columns
If I have a date.frame formed by the vectors: V1<-c("A","B","C","D","B") V2<-c("C","D","C","B","B") V3<-c("D","D","C","A","A") V4<-c("C","B","C","A","C") G1<-c("C","C","A","A","B")…
-
2
votes2
answers195
viewsHow to load all functions from a folder?
Suppose the folder "D:" has several functions that I use in a project. How to load all these functions with a script?
-
2
votes3
answers830
viewsLoop in R with indexing and matrix
We’re trying to use the command for to run a y function (say y=5+3x+4z) varying the values of z (let’s say z is a combination of 5 values z=c(1,2,3,4,5)) and that x is a normal distribution of size…
-
2
votes1
answer270
viewsHow to download multiple urls in R?
I need to extract several text files that are organized in annual folders at the following url: http://www.rsssfbrasil.com/tablesae/ How do I extract multiple folders at once? For example, if I want…
-
2
votes3
answers304
viewsHow to create a Standard Deviation Mobile Window (R)
A being the matrix below the return on shares (ret_matriz) for a given period. IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.040630825 -0.027795652 -0.052643733 -0.053488685 -0.048455772 -0.061668282…
-
2
votes1
answer361
viewsUnderstanding the Survey
Come on... I’m studying the Survey package I started studying this page http://www.ats.ucla.edu/stat/r/faq/svy_r_scpsu.htm but my questions are more basic I have already uploaded the following…
-
2
votes1
answer1606
viewsCorrelation Matrix in R (cov.wt)
In the cov.wt function in R it is possible to obtain as a result only the Correlation Matrix ? cov.wt = Returns a list containing estimates of the Weighted covariance Matrix and the Mean of the…
-
2
votes1
answer39
viewsHow to generate colored labels in comparison.cloud?
Below is an example of the code to generate the cloud: comparison.cloud(tdm, random.order=FALSE, colors = c("tomato", "wheat", "lightblue","lightgreen")) Words are easily colored with the above…