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
-
1
votes0
answers74
viewsHow to predict the various statistical models generated in R in Power BI?
I trained several models in the R, like these: iris2 <- data.frame(zzz= sample(c(0, 1),size = length(iris$Sepal.Length), replace = TRUE), iris) for (i in unique(iris$Species)) { saveRDS(glm(zzz ~…
-
1
votes1
answer31
viewsBase Reading Step Bar
I am developing an app in Shiny that the user climbs a spreadsheet and is calculated some statistics from that base. I would like the moment the database is being read, not displayed in the upload,…
-
1
votes1
answer40
viewsProblem converting JSON to dataframe in R
I want to extract a JSON content from a website and convert it into a dataframe Website is https://schutz-shoes.com/products/amaia-sandal-metallic-leather?color=ouro%20gold Inside that site,…
-
1
votes1
answer185
viewsHow to import a large . txt file with data.frames and columns?
Hello, all right ? Precise import a large db that is in .txt and divided into 20 parts of 5Gb each (approximately). Within that base there are three data.frame, with 3 different column quantities.…
-
1
votes3
answers55
viewsConvert a factor (of real numbers) into a numerical vector
I know there’s such a thing question. But in my case, there’s a difference: want to convert the factor into a numerical vector without removing the separator (either semicolon). Dice: df <-…
-
1
votes2
answers93
viewsRegular expression by string index
Consider this variable: x <- c('horccaeon', 'coleon', 'volues', 'mol', 'nao', 'tom', 'nada', 'auio', 'aqoio') I used the following regex to extract strings with the second letter o:…
-
1
votes2
answers57
viewsHow to replicate a line with a difference of names on it? R
I have a function and I didn’t want to have to create a new line in it whenever I add a new object to it: a<- function(x1,x2,x3,x4){ res_x1= x1*4.95+x1 print("resultado x1") print(res_x1) res_x2=…
rasked 5 years ago Vinicius Soares 31 -
1
votes2
answers251
viewsR - brazilmaps (border of states)
I created a map of SP and MG states using brazilmaps(). On this map I filled some cities with values. However, I would like to make the border of states appear on Plot. How do I do that? Follow what…
-
1
votes1
answer54
viewsChange x scale to range from 0 to 100 but showing decimal variations
Hello, I need to plot the decimal variations on the x-axis and vary from 0 to 100 fevmt=c(91.9, 92.1, 92.3, 91.4, 91.8, 90.1, 91.8) a1 =c(91.9, 100) b1 =c(92.1, 100) c1 = c(92.3, 100) d1 =c (91.4,…
-
1
votes0
answers58
viewsError loading dataframe with JSON file data
I am getting the error below when loading a JSON file to a dataframe. Error in (Function (..., Row.Names = NULL, check.Rows = FALSE, check.Names = TRUE, : Arguments imply differing number of Rows:…
-
1
votes0
answers36
viewsPenalty matrix in generalized additive models with smoothing through P-splines
I’m studying generalized additive models using the package MGCV of R. Below is an illustrative example for a certain adjustment using the Gam function. library(mgcv) data(mcycle) attach(mcycle)…
-
1
votes3
answers100
viewsHow to generate graphics from a file using a loop in R?
I would like from an archive, which in the case of public safety indicators of Rio de Janeiro, generate charts for each year of the database, showing the progress of these indicators over the…
-
1
votes0
answers30
viewsPlot lines from two different matrices in R?
I have two matrices with same number of rows and different number of columns. Each matrix is a sample, each row is a compound (1,2 and 3), and each column is the residue number. The value in the…
-
1
votes2
answers70
viewsLoop for inside a list with a group argument function
I have this data: df_1 <- data.frame( x = replicate( n = 3, expr = runif(n = 30, min = 20, max = 100), simplify = TRUE ), y = as.factor(sample(x = 1:3, size = 30, replace = TRUE)) ) And this…
-
1
votes2
answers175
viewsImporting and cleaning several text files in R
I’m working on a set of interviews I got from a database in my work, each in a separate text file (a normal file with a multi-line transcription). Each interview will be part of data frame as a…
-
1
votes0
answers272
viewsError accessing Rstudio 127.0.0.1
I’m trying to access Rstudio and this error appears: 127.0.0.1 refused to connect. Try: Check the connection Check proxy and firewall ERR_CONNECTION_REFUSED if I go in cmd and der ping: C: Windows…
-
1
votes1
answer44
viewsIf_else and Filter
I’m trying to give a filter: library(tidyverse) library(lubridate) filter(indicesBrutos, if_else(day(NomDataIn) != 1, filter(Mes >= NomDataIn-30, Mes <= CMData)), filter(Mes >= NomDataIn,…
-
1
votes1
answer104
viewsSQL and R - Download data from a table with space in names and integer filter
I have a database in Postgresql and would like to download a table, but with some filters. The column 'CNAE 2.0 Class' is an integer. library(RPostgreSQL) PIA_Estab <- dbGetQuery(con," SELECT *…
-
1
votes0
answers87
viewsI can’t find my function in the R package
I did a function on R and included it in my package I made. I clicked on clean and rebuild and soon after, I checked. Also, my function has been exported, and it appears listed in the NAMESPACE doc…
-
1
votes1
answer62
viewsHow to adjust the regression line so that 90% of the lines are below the line?
I have the following data set in R: x <- c(0.1, 3, 4, 5, 9, 12, 13, 19, 22, 25) y <- c(5, 12, 17, 23, 28, 39, 26, 31, 38, 40) bd <- data.frame(x, y) My question is how I do in R to generate…
-
1
votes1
answer60
viewsHow to create numerical samples based on multiple conditions on multiple vectors?
Given the following data frame: df <- tibble::tribble( ~pass_id, ~km_ini, ~km_fin, 1L, 0.89, 2.39, 2L, 1.53, 3.03, 3L, 21.9, 23.4, 4L, 23.4, 24.9, 5L, 24, 25.5, 6L, 25.9, 27.4, 7L, 36.7, 38.2,…
-
1
votes1
answer655
viewsReorder the columns of a bar chart and its caption
When processing and plotting data in R using tidyverse, it by default leaves the chart bar order in the original column factor order: library(tidyverse) mpg$trans <- as.factor(mpg$trans) mpg…
-
1
votes0
answers71
viewsForecast of traffic volume
Hello, good afternoon, sir! I am developing a model that will predict the volume of vehicles each day of the year, but I am encountering difficulties because of the functions that make the forecasts…
-
1
votes1
answer61
viewsColor the axis source of a dendrogram in ggplot2 according to a categorical variable
Suppose I need to build a dendrogram on R: library(tidyverse) library(ggdendro) ggdendrogram(hclust(dist(iris[, -5]))) + theme(text = element_text(size = 8)) My chart is created, but I want to…
-
1
votes1
answer35
viewsR and Postgresql - AND/OR and BEETWEN/NOT BEETWEN how to help logic?
I need to get some information from the postgresql database through R . However, the filters are not downloading what I want. I would like to download only the cnaes of companies with cadastral…
-
1
votes1
answer62
viewsDotplot in R include vertical line and dots of different colors
I needed to include in the code below a vertical line, for example, at position x = 5 and that all points with x smaller than 5 have another color, for example blue. The values of a variable can be…
-
1
votes2
answers673
viewsHow to sum a column in R
I am using a database with several dates and would like to sum up the values of the last available date, I can filter the data.frame by date, but I can’t make the sum of the values, I’m trying to…
-
1
votes1
answer57
viewsHow do I insert NA, or deviation of missing data, when making Webscraping (rvest) from a page in R?
I’m downloading the hotel rates at Natal- RN by the Booking.com website. The code is programmed to download according to the check-in date the hotel name (nomes_i), the name of the room (quarto_i)…
-
1
votes1
answer116
viewsHow to change the graph structure in ggplot2?
I used the following command line from ggplot2 in R to generate the attached graph: g1 <- ggplot(count, aes(x=cluster, y=Reads)) + geom_point(shape=1) + facet_grid(. ~ Spp) ggplot(count,…
-
1
votes1
answer265
viewsRemove "Nan" from a data.frame in R
I have a data.frame with two columns that have some NaN and Inf and I’d like to replace them with NA. I was using this code, but it didn’t work: library(tidyverse) dados <-…
-
1
votes1
answer71
viewsSeasonality chart with ggplot2
I have an example graph that shows the seasonality of a given per month over the years. I would like to adapt the chart to days of the week, I have the example code, but I’m not able to adapt it.…
-
1
votes1
answer255
viewsHow to change bar graph border size in ggplot2
I have a bar graph on the R made with the function geom_col. I would like to decrease the border size, because it is not showing the chart fill. I tried using the argument width, but is only…
-
1
votes0
answers32
viewsInstallation problems for Rmysql / Ubuntu 18.04 package
R version 3.6.3 (2020-02-29) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.4 LTS When trying to install the Rmysql package using the instruction: install.packages('RMySQL') I…
-
1
votes1
answer70
viewsHow to change scales of a multifaceted graph in ggplot2
I have a graph composed of 27 subplots, each corresponding to a state, some states, such as SP and RJ have values much higher than other states and the scale of the graph is in larger intervals. Is…
-
1
votes0
answers32
viewsHow to edit ylab2 in doubleYScale?
Hello, I need to edit ylab2, within the latticeExtra::doubleYScale. As you can see in the image, the axes captions, they’re different sizes, I need them to be cex=1.4. follows the data:…
rasked 4 years, 6 months ago Jean Karlos 646 -
1
votes0
answers237
viewsUsing the "as Numeric" function in Rstudio
Hello! I am trying to create a new binary variable to an existing database using the following code: leaders$warbefore <- as.numeric(leaders$interwarbefore == '1', leaders$civilwarbefore == '1')…
-
1
votes0
answers91
viewsRstudio - Update and add new data
Hello, I’m looking for IBGE data (library("sidrar")), df <- get_sidra (api = "/t/1846/n1/all/v/all/p/all/c11255/90707/d/v585%200") #Selecionando as colunas que me interessa df1 <-…
-
1
votes0
answers58
viewsUse R inside a . ipynb
Hello! I have the following question: I need to use the following R packages for academic work: BETS (https://cran.r-project.org/web/packages/BETS/index.html) getDFPdata…
-
1
votes2
answers87
viewsUpdate data and add new data
I am looking for data from IBGE (SIDRA), I need to add the last data and update the 3 previous periods, without changing or messing with the old data. Follows the code: library(sidrar) df <-…
rasked 4 years, 6 months ago Larissa Castro 33 -
1
votes0
answers20
viewsGenerate a distribution for each i element of my sample
I am interested in applying this model described in the variable d for each of the 1024 elements described in my second for and finally store the percentiles of each of these distributions in a…
rasked 4 years, 6 months ago Rafael Setti 11 -
1
votes1
answer53
viewsR - How to generalize a function if data is missing.frame
I created the function below to calculate the descriptive statistics of certain companies separated between the 5 regions of Brazil and the total and present in a table. library(tidyverse)…
-
1
votes2
answers43
viewsI want to overlay two graphs
I’m trying to overlay two graphs, one from the binomial distribution and the other from Poisson. They should have close values for large N. N here was called x and saved the values generated by…
rasked 4 years, 5 months ago Anderson Costa 15 -
1
votes1
answer63
viewsHow to put a delay inside a function in R?
Hello! I would like to put a delay within a function that I am creating to join N-graphics. I realized that in some cases, my function does not expect the eval(parse(text=paste())) generate all…
-
1
votes1
answer88
viewshow to find the average in a table of classes
I wonder how do I find the average in the frequency table using R. I tried doing: sum(n.div * p.m)/5000 But the result is very discrepant (6900). When I do in any other table, the same procedure is…
rasked 4 years, 5 months ago Di82Rquant 23 -
1
votes2
answers462
viewsHow to sort data on Y-axis using ggplot2 in R
I’m charting some data on a Bubble Chart using the package ggplot2 of R. My data is out of order on the Y axis. I would like you to follow the order of the numbers present in the names, for example:…
-
1
votes1
answer83
viewsError while scaling on ggplot map
I’m using this Shape file to make a map: link library(rgdal) library(ggplot2) mapadf <- readOGR(dsn= "/rj_municipios", layer = "33MUE250GC_SIR") mapadf <-fortify(mapadf) The map stays as I…
-
1
votes1
answer110
views(R Language) How to ask a user for data frame input?
I’m doing a function that traverses data frames in search of non-numerical values. To do so, I have to ask the user to provide a data frame as input. Thus, I write: data.frame <- readline(prompt…
-
1
votes1
answer448
viewsError reading file . xlsx in R
I have a file .xlsx which I need to read in R. The tab is variable, so I use a code first to check which tab is the most recent, but when using the function read_excel package readxl, returns the…
-
1
votes0
answers37
viewsInvalid character in R
I turn the [ ] character into an A letter, within a R data.frame. It works perfectly, though, when I create a ". bat" to run this algorithm automatically by windows tasks it displays the following…
-
1
votes2
answers84
viewsWarning message: Those produced when calculating confidence intervals
I am trying to estimate the upper and lower limits using the 95% confidence interval, but the R returns the following message: Warning message: In rnorm(nrow(df), media/-0.832, media/-0.399) : NAs…
rasked 4 years, 4 months ago Milton de Paula 305