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
-
2
votes1
answer53
viewsIs it possible to check an error of a function with an if()?
I’m using the package gtrends to pull some data from google.. This package allows you to download 5 Keywords at a time. That’s why I’m using a for() However, some Keywords I need to query are not in…
-
2
votes1
answer70
viewsHow to plot a time series graph with ggridges?
I’m trying to plot a graph of cases per state with geom_density_ridges package ggridges, to stay that way: But by plotting the graph, it’s getting that way, all with the same line: What am I doing…
-
2
votes2
answers115
viewsRegression Graph in R or Python
It is possible to play this Regression graph in R or Python? Obs. This graph was produced using the Acquire 4 QAQC object. Link And this is the model I’ve created so far. dados =…
-
2
votes0
answers34
viewsAlluvial Charts - Flow does not appear
I have a table like this: Organization Timeframe Code id 1 Agencia1 Fortnight 1 International Affairs 1 2 Agencia2 Fortnight 1 Environment 2 3 Agencia2 Fortnight 1 Health 4 4 Agencia2 Fortnight 1…
-
2
votes1
answer38
viewsWhy does the "nls" function of R not converge even with the initial curve very close to the points?
To adjust the following points with the function whose initial kick is represented by the line: But I get the following message: Error in nls(y ~ A * (1 + erf(E * B * (x - C)/sqrt(2))) * dnorm(B *…
-
2
votes1
answer58
viewsProblems with sum() function inside summarise using plyr and tidyverse!
Hello, good afternoon! I’m finding it difficult to use tidyverse, to perform a stacking function + summarise(soma=sum(value)) + pop =…
-
2
votes1
answer152
viewsHow to transform each digit of a number into an element of a vector in R?
For example: numero <- 516481 how can I transform each digit of that number into an element of an array, in order to access them by index? For if numero is a vector with each element being a…
-
2
votes1
answer121
viewsHow to change the colors of geom_points in R
library(tidyr) library(dplyr) library(ggplot2) library(lubridate) Suppose the following df: Ano<-c(2012:2020) Janeiro<-c(112,127,121,131,150,158,137,165,164)…
-
2
votes1
answer73
viewsI would like to edit my chart by displaying a single maximum value
Hello guys I’m having trouble displaying a value on my chart, it’s a graph of the evolution of the number of deaths in my city, my X axis is composed of March dates so far, and the Y axis with the…
-
2
votes2
answers190
viewsLabel data in column charts at "Dodge" position in R
I am working with the following data frame: library(tidyverse) df<- data.frame(Ano=c(2017, 2018,2019,2020), Vagas=c(16, 14, 27, 32), Inscritos=c(70, 107,74,88), Aprovados=c(15,14,17, 12)) df Ano…
-
2
votes1
answer79
viewsCalculate percentage with dplyr::add_count
how it would be possible to calculate percentages with the dplyr::add_count()? To calculate with the dplyr::count() is very simple, as follows: library(tidyverse) dt <- Titanic dt %>%…
-
2
votes1
answer88
viewsGraph of trends in ggplot2
How to play the chart below using ggplot2? Data and ggplot2 code I’m trying ano<-c("2009", "2011", "2013","2014","2016","2017","2018","2019") mean.est<-c(0.975, 1.204, 1.504, 1.741,…
-
2
votes1
answer60
viewsApply a function varying between categories in R
I need to calculate the elasticity - price of demand of a specific product (percentage variation of the quantity demanded divided by the percentage variation of the price). For that I made the…
-
2
votes0
answers168
viewsWhat is the best R package to plot data on maps in Brazil?
From what I researched here in the OS and Google, there are at least three different packages to build maps of Brazil in R. The package "geobr"; The package "brazilmaps" A combination of packages…
-
2
votes0
answers46
views -
2
votes1
answer56
viewsError when colorizing bar graph and caption with the pal.bands function
I’m trying to reproduce the chart below: However, I am not able to color my chart through the function pal.bands according to the information that is in the spreadsheet below: The data is found in…
-
2
votes0
answers27
viewsHow to count the quantity in variable using boxplot, not the frequency?
I’m trying to create a boxplot of the amount of respirators per state, but when I plot the R counts the frequency of respirators not the amount per state. There I have the following information: I…
-
2
votes0
answers46
viewsHow to group data in R?
I wonder if it has any function in the R that makes it possible to make a kind of "grouping" of the data. For example, a way to get this spreadsheet to return something like: Codigo Grupo Qtde Total…
-
2
votes1
answer245
viewsRelative Frequency Table - R / R Studio (% Daily Sales Determined Date/Product)
I have tried in every way to write a code that creates a relative frequency table, but I could not. I have a dataframe with the following variables: RANGE_DIAS: Interval of days between order date…
-
2
votes0
answers57
viewsError reading Skott-Knott test file in R
I’m a beginner in R and I’m not being able to perform the Skott-Knott test in the Expdes.pt library. # expdes.pt library("ExpDes.pt") options(digits = 4) # with transformed data dic(db$Insetiscida,…
rasked 3 years, 12 months ago Matheus Pacheco 21 -
2
votes0
answers32
viewsRecoding factors from the relative frequency of levels and the mean value of a continuous variable
I have a dataframe with several variables of the type factors that I need to recode. An example of my data is the following: structure(list(ID = 1:100, faixa_etaria = structure(c(2L, 7L, 3L, 4L, 5L,…
-
2
votes2
answers64
viewsExport Summary() as data-frame
I want to export Summary() from my data-frame to look like this: For this, I built my code as shown below: dados1 <- read.csv("dados-originais.csv", header = T, skip = 0, sep = ",")…
-
2
votes2
answers39
viewsGraphic editing in ggplot2
How should I proceed to replace the caption text in the chart below "Mean.est" and "Mean.Obs" to "est" and "Obs"? Reproductive example: ano<-c("2009", "2011",…
-
2
votes1
answer28
viewsOverlay the legend of the estimated lines using the stat_poly_eq function
I adjusted different models considering the response variable (massaseca) as a function of (time) for each treatment level (content) using the ggplot2 package combined with the stat_poly_eq…
-
2
votes2
answers64
viewsSelect columns from a base without having to read the whole file
I have a file in . csv VERY large that I can’t read in R. I tried so: dados19 <- read.csv("microdados_censo_superior_2019/dados/SUP_ALUNO_2019.CSV", sep="|", dec=".") It is the census of higher…
rasked 3 years, 10 months ago Alexsandra Gomes 23 -
2
votes0
answers31
viewsR Language: Format string according to the first character
I am writing an R script to convert data that is in text files with fixed width fields for CSV files. It happens that in addition to the transformation I do some "formatting" in the data and has a…
rasked 3 years, 9 months ago Everton da Rosa 755 -
2
votes2
answers53
viewsHow to count repetitions in a range using length(which()) in R
I create the data frame called producao: producao<-data.frame(aluno = c("Pedro", "Joao", "Marcio", "Pedro", "Joao", "Pedro", "Marcio", "Marcio", "Marcio"), qualis = c("A1", "B2", "A1", "B2",…
-
2
votes1
answer33
viewsHow to make a subset in a zoo-type series choosing certain years or months?
I have the following series: library(zoo) zoo_serie <- zoo(1:length(seq.Date(as.Date("1991-12-01"),as.Date("1998-12-31"),'day')),seq.Date(as.Date("1991-12-01"),as.Date("1998-12-31"),'day')) I…
-
2
votes1
answer66
viewsHow to save the generated graphics files (in png) within a loop
I’m trying to generate png files of graphics that are inside a loop. I tried to do with the function ggsave but I cannot insert inside the loop and outside the loop generates the empty file.…
-
2
votes1
answer39
viewsDiagnostic analysis in mixed effects models via Plot Half-Normal chart
I am intending to perform the Plot half-normal chart for a mixed effects model that has been adjusted using the package lme4. To visualize the diagnostic analysis of this model, I intend to use…
-
2
votes1
answer36
viewsHeterocesarean mixed effects model via lmer function
I am adjusting a mixed effects model which due to observed heterocedasticity was necessary to include an effect to accommodate it. For this purpose, using the function lme package nlme this was easy…
-
2
votes2
answers63
viewsCreate hatched area below normal distribution curve in R
I would like to create a gray hatched area, just like the one in the image below. I plotted the curve, with the data as follows: dados <- c(149.3355, 140.3779, 145.7254, 149.8931, 139.6168,…
-
2
votes1
answer53
viewsProblems when grouping information through ifelse and case_when functions
I am trying to group the information contained in each of the Brazilian states into regions. Initially I checked the distribution of these in each state through the function table. Dice:…
-
2
votes1
answer18
viewsExpand / insert new rows into a data frame based on the value of a discrete variable
I have a data frame with summarized data volumes of a certain product configuration. I need to expand the lines according to the "volume" variable of each summarized line. I tried using add_row()…
-
2
votes1
answer45
viewsTransform a list (list) into a database (data.frame)
I have the list below. I would like to turn it into a data.frame (or Tibble): dados.lista <- list(id = 2287276L, uri = "https://dadosabertos.camara.leg.br/api/v2/proposicoes/2287276", siglaTipo =…
-
2
votes1
answer26
viewsHow to make a filter based on a condition?
I have a date.frame with two columns (CLASSWK and IND) and I’d like to apply a filter based on one condition, but I’m unable to do that. I have a column CLASSWK, that I only want to keep values that…
-
2
votes1
answer29
viewsX-axis values in bold
How to render the characters of the x-axis of the graph below in bold? library(ggplot2) library(tidyr) TCH <- data.frame( Período =c("Jun", "Jul"), CV6654 = c(9.38, 26.14), CTC9002 = c(16.27,…
-
2
votes1
answer40
viewsVanishing symbol when saving graphic image
In the annotations inserted by the argument annotate in the chart below in one of them has the symbol " ", but when saving the image as PDF the symbol disappears and appears "..." instead. I’d like…
-
1
votes1
answer101
viewsConvert Character with precision
whereas the content of a certain variable is "001" class Character. I need to transform that character to numeric. If I do as.numeric(), he returns me 1. I want you to return me exactly 001, is it…
-
1
votes3
answers517
viewsComparing matrices of different sizes in R
I have the following situation : all_sec = Matrix of all possible assets in a portfolio all_sec <- matrix(c("SEC1","SEC2","SEC3","SEC4","SEC5"),ncol=1) portfolio <- composition of a portfolio…
-
1
votes0
answers56
viewsassociation between variables
id Acidente id_Vitima Sexo_Vitima Faixa_etaria Gravidade_acidente 1 1 1 7 1 2 1 1 3 3 2 1 2 3 3 3 1 2 6 2 3 2 1 2 2 3 3 1 7 2 3 4 2 7 2 I intend to make an analysis of the association between the…
-
1
votes2
answers140
viewsscript about the R program
I am using R to extract data in format .h5. I’m getting it done. However, they are data of 200 years, and monthly. For now, I can only call through the program a file every month at a time, but I…
rasked 9 years, 4 months ago Luciana Vieira 11 -
1
votes2
answers344
viewsHow to make a matrix in R that its inputs are equal to i * j?
I want a Generic matrix 10x10, that their entries are equal to i*j, where i is the column and j the line
-
1
votes1
answer67
viewsHow to store the address of the equal elements between vector and matrix?
I’m having a question, I’d like to take the element a[1] and compare with b[1,1] and count as a hit, then the element a[2] compared to b[2,1] and so on, always by column. Then I want to compare the…
rasked 9 years, 1 month ago Wagner Jorge 1,377 -
1
votes4
answers1242
viewsHow can I save a list or export a list object in R?
I have a list object, similar to the one below: x<- list(cod = 1:10, taxa = exp(-3:3), logico = c(TRUE,FALSE,FALSE,TRUE)) What is the best way to store this object, in *.R , *.csv or _ _ _ ?…
-
1
votes1
answer1174
viewsHow to find the position of equal elements in character vectors (Character)?
Considering: a<-c("Ano", "X2751006.", "X2751007.", "X2751008.", "X2751015.", "X2751017.", "X2751018.", "X2751025.", "X2752001.", "X2752006.", "X2752007.", "X2752008.", "X2752009.", "X2752010.",…
-
1
votes1
answer418
viewsHow to plot several graphs on an A4 sheet with defined margins?
To illustrate the question I considered the hypothetical situation below, using the libraries ggplot2 and gridExtra. library(ggplot2) library(gridExtra) df<-data.frame(x=1:10,y=1:10)…
-
1
votes0
answers68
viewsCalling C for R?
How do I program in C inside the R or call a code of C in R? I’ve read a few tutorials, but I don’t quite understand.
-
1
votes3
answers1888
viewsA: Remove columns from a dataframe
How can I remove columns from a dataframe other than as follows? > df x y z 1 1 6 A 2 1 5 B 3 2 4 C 4 2 3 D 5 3 2 E 6 3 1 F > df <- data.frame(df[,1:2]) > df x y 1 1 6 2 1 5 3 2 4 4 2 3…
rasked 8 years, 11 months ago Capitão Ahab 565 -
1
votes2
answers222
viewsQuestions about the model y=a/(x+b)?
Help! Hello everyone, does anyone know this model y = a/(ln(x)-b-e)? I would like any information about it to make the adjustment in R. The idea is to know if there is any restriction between the…
rasked 8 years, 10 months ago DiogoCosenza 41