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
votes1
answer307
viewsBarplot (bar graph) of numerical versus categorical variable in R
How to plot a bar graph on the R in which the eixo x I have a categorical variable (with 4 categories: frequent, sometimes rare, never) and in eixo y the average of a numeric variable (Y=0:13)? How…
-
4
votes1
answer71
viewsDate formatting for Gtrends (gtrendsR package)
How to resolve this package formatting error gtrendsR(actually how I check the current native formatting and adjust it)? Error in as.POSIXlt.character(x, tz, ...) : character string is not in a…
-
4
votes2
answers381
viewscombine vectors per line in R by filling voids
I have two vectors: a <- c(1,2,3,4) b <- c(1,2) I want to create a matrix combining the vectors per line that looks like this: 1 2 3 4 1 2 0 0 That is, unite two vectors by rows and fill the…
-
4
votes2
answers133
viewsDirect (and beautiful) solution to fix base using dplyr
I have the following basis of defaulters: df <- data.frame( lead_15 = c(1,0,0,0,0,1,0,0,1,0,0,0,0,0,1), lead_30 = c(0,0,0,1,0,0,1,1,0,1,0,0,0,1,0), lead_60 = c(0,1,0,0,1,0,0,0,0,0,1,1,0,0,0),…
-
4
votes4
answers4556
viewsHow to change the order of appearance of Columns in a Data Frame?
I’ve got this df mounted on the R: Produto Classificação Comun Quilo Indice 1 ABACAXI HAVAI A GRAUDO 3,32 2,2 2 2 ABACAXI HAVAI B MEDIO 2,81 1,8 3 3 ABACAXI HAVAI C MIUDO 2,21 1,4 4 4 BANANA MACA -…
rasked 7 years, 8 months ago Danilo Imbimbo 533 -
4
votes1
answer376
viewsExtract table from a website for Rstudio
Hello, I want to take the table of the Brazilian, for example this site "http://globoesporte.globo.com/futebol/brasileirao-serie-a/" and extract to a dateset in Rstudio, so that whenever the table…
-
4
votes2
answers1312
viewsHow to change the "Key" orientation of a Caption in ggplot?
how can I change the "key" of the caption below, so that it stays in the horizontal position, without changing the vertical lines of the chart. Also, how to leave the caption background with the…
-
4
votes1
answer256
viewsHow to play a graph that was created with the Plot command using ggplot2?
How to play the chart below using the ggplot2? I don’t know how to add the various charts into one layer single! bs<-function(t,mu,phi){…
-
4
votes1
answer2685
viewsHow to color the legend according to the chart in R
Hello guys I have a chart on R and would like to make the caption equal to the chart. follows below the command used and the graphic image. control = c(100,100,100,100,100) dez = c(100,90,0,0,0)…
-
4
votes1
answer76
viewsCreate new database from random values with loop or other method
I have three dataframes with different number of lines and I would like to create a new dataframe with 100 random values from these dataframes and based on three criteria: A - Column a and b will…
-
4
votes1
answer230
viewsScrape of MTE mediating system
I’m trying to make the Scrape of the Ministry of Labor mediating system. Basically, I want the relationship of collective agreements and conventions:…
-
4
votes1
answer758
viewsGrab URL table from R
I need to do it here: library(xml) URL <- "http://globoesporte.globo.com/futebol/brasileirao-serie-a/" tabela1 <- readHTMLTable(URL, which = 1, colClasses = ) tabela1$V3 <- NULL…
-
4
votes1
answer1978
viewsProblem with forecast in R
I’m trying to make a relatively simple GDP forecast, but I’m finding the following mistake: **Error in model.frame.default(formula = y ~ t2, drop.unused.levels = TRUE) : comprimentos das variáveis…
-
4
votes3
answers1792
viewsColumns with numbers of different rows, how to join?
I have some time series (monthly) that end in different months, for example, some end in March 2017, others in April 2017 and some even in May 2017, follows example: 228 2016-12-01 1.12 229…
rasked 7 years, 6 months ago Danilo Imbimbo 533 -
4
votes2
answers164
viewsHow to check if a certain sequence of Elements exists in R?
I have a vector like this: vectorx<-c(3,3,1,1,1,2,2,2,2,2,2,2,2,2) And I want to check if the sequence 3,3,1,1,1,2 exists. It turns out that this sequence can be in any vector position, I just…
rasked 6 years, 11 months ago Vivian Ribeiro 195 -
4
votes3
answers5016
viewsReplace NA in R language
I would like to replace NA (Missing) for a word. I have the following data: structure(list(NOME = c("ABC", "ADD", "AFF", "DDD", "RTF", "DRGG" ), TIPO = c("INTERNACAO", "", "CONSULTA", "EXAME", "",…
rasked 6 years, 11 months ago Bruno Avila 867 -
4
votes1
answer612
viewsImport data from central bank to R
I would like to know if it is possible and how to import data from the central bank directly to R If there is a specific api or package to access the time series
-
4
votes1
answer92
viewsFunctions R - Strange Character
I created a function in the R and detected a strange character appearing on the return of the function. Can you explain to me? Here is the function: funcao_categorica <- function(xx){ rr <-…
-
4
votes2
answers206
viewsScatter charts fixing a response variable
Suppose I have an interest in the dataset iris, already present in the memory of R: head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2…
-
4
votes1
answer1248
viewsUsing Mysql with R in the Rmysql package
I am new when the subject is Mysql and installed this program to use with R. I managed to install the Rmysql library, following tutorials I found on the Internet and in the course I am doing in…
-
4
votes2
answers4518
viewsSelect multiple lines of a data.frame from the highest R values
I have the following date.frame in R: df <- data.frame(x = c(10,10,2,3,4,8,8,8), y = c(5,4,6,7,8,3,2,4)) df x y 1 10 5 2 10 4 3 2 6 4 3 7 5 4 8 6 8 3 7 8 2 8 8 4 First point: I would like to get…
-
4
votes2
answers158
viewsPlay a chart in R
I made graph 1 below in R, from the code: library(truncreg) set.seed(1) x <- sort(rnorm(50)+3) y <- 3 + 1*x + rnorm(50,0,0.3) compl <- data.frame(x,y) y[y>6.5] <- 6.5 sample <-…
-
4
votes1
answer688
viewsError in Plot.window(...) : need Finite 'ylim' values
I have a continuous variable whose n=15000 comments and 451 Als. When rotating the qqnorm For the evaluation of normality, I verified that it does not present normality and therefore I applied a…
-
4
votes1
answer524
viewsPdf reading via R
I need to convert the PDF data below into a data frame: http://www2.alerj.rj.gov.br/leideacesso/verArquivo.asp?idArquivo=635 Doing a search for found the How to Read PDF Data in R. I had some…
-
4
votes1
answer730
viewshow to place histogram values on top of bar
I’m using the Histogram command from the Lattice library on R. I would like to know how I can put the value on top of the bars, value I speak is the histogram count. Ex:…
-
4
votes1
answer1440
viewsArrange bars of a bar graph in R
I’m filling the following data into the R to generate a bar chart: structure(c(5483L, 28034L, 7995L, 5199L, 6785L, 7452L, 7692L), .Dim = 7L, .Dimnames = structure(list(c("dom", "qua", "qui", "sáb",…
-
4
votes1
answer579
viewscreation of gif in r
I’m trying to create a Plot GIF below: x<-NULL y<-NULL for(i in 1:500){ y[i]<-sum(rnorm(i))/i x[i]<-i plot(y~x, type="l") abline(y=0) Sys.sleep(0.25) }…
-
4
votes1
answer309
viewsSaving values for all iterations in R
Hello, I am making a code in R to calculate the various values of a fuzzy code (using the package "Sets"). I made the logic for him to calculate three Fuzzy variables from the smallest to the…
rasked 7 years ago Leonardo Grando 55 -
4
votes3
answers11076
viewsTurning factor into numeric R
Good night! I am doing a job where I import a base and after the import I create a range of values. Ex. I import the base with the read.csv dados <- read.csv(base, header=TRUE, sep=',') Put in…
-
4
votes1
answer57
viewsadd column that shows how many times a value has repeated from that row back
I’m having trouble creating a column that shows how many times a row has repeated itself, but not in the entire dataset, but in that line back. Ex: NOME ANO MES COLUNA_QUE_QUERO_CRIAR A 2016 4 1 A…
rasked 6 years, 12 months ago Geovani Ferreira 129 -
4
votes1
answer94
viewsOrganize a time series
I have a base with collected information on weight gain per animal. They were collected at different intervals for each animal. Follow part of the base just below Animal Dia Ganho 5 2 0.99 5 9 1.01…
-
4
votes2
answers114
viewsWhat do you call the previous month in the R?
I need the R to tell me month before we are, that is, we are in "2018-05" and I need it to give me "2018-04". So far my solution has been: format(Sys.Date()-as.integer(format(Sys.Date(),…
-
4
votes1
answer3746
viewsHow to change the font on a chart in R?
I want to use the source Times New Roman on the chart, but the R/Rstudio returns an error message saying not to find it. Obviously the source is somewhere because I use MS Word, for example. A while…
-
4
votes1
answer1856
viewsHow to take Dunnett’s test on R?
Assuming that I performed the ANOVA test on my data and gave significantly different, I would like to perform the Dunnett test precisely to compare my treatments with the control group. I should use…
-
4
votes3
answers3012
viewsAggregate function on R
Good afternoon. I’m using the function aggregate to group some data. However, I am only using one variable to add up. I would like to use more than one variable. Is this possible? I am using the…
-
4
votes1
answer241
viewsDraw lines from a specific point and angle
I’m looking for a way to draw a line from a point and an angulation (azimuth) and then construct a polygon with the intersection of these lines. base <- tibble::data_frame( id = c(1, 2, 3), x =…
-
4
votes1
answer334
viewsHow to plot a plot with ggplot
I have the following date.: sample OPN1SW OPN1MW OPN1LW RHO OPN3 OPN4 OPN5 1: GTEX-11WQK-1026-SM-5EQLX 2.365 0.0000 0 4.138 86.322 40.199 12.533 2: GTEX-XQ3S-1426-SM-4BOPR 22.317 0.0000 0 30.693…
-
4
votes1
answer176
viewsFilter in dplyr constrained by the maximum variable value of db Gapminder
I’m making the filter on df gapminder, generating a df empty when I use the variable gdpPercap: library(gapminder) # versão 0.2.0 library(dplyr) # versão 0.7.2 gapminder %>% filter(year == 2007,…
rasked 6 years, 10 months ago Mario Bastos 41 -
4
votes1
answer73
viewsMake a matrix of origins and destinations
I need to fill a table with origins and destinations so that each cell contains the total number of people leaving from one location to another. The database has an id for each observation, as well…
-
4
votes1
answer316
viewsPredict function in GLMM
Edited When we use a traditional logistic regression and make a prediction in R for example: library(dplyr) n = 300 xx<-c("r1","r2","r3","r4","r5") xxx<-c("e1","e2","e3") p=0.3 df1 <-…
-
4
votes2
answers116
viewsReplacing for the Lapply function in R
This is my list lista1<-list(c(1, 2, 3, 4, 5), c(6, 7, 8, 9, 10), c(11, 12, 13, 14, 15 ), c(16, 17, 18, 19, 20), c(21, 22, 23, 24, 25)) I build a new list the way below. novalista <-…
-
4
votes1
answer893
viewsSum of the regression square of R models
The models presented are different in only one additional coefficient (f), which multiplies the independent variable (x), allowing the calculation of the increase of the sum of the square of the…
-
4
votes1
answer59
viewsReorganize data frame in a list using dplyr in R
This is my dataframe: dput(df) structure(list(ind = structure(c(16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437,…
-
4
votes1
answer311
viewsCorrplot package
How can I add significance to correlation without overlapping between the symbol (*) and the correlation value?? So that it looks like in the picture…
rasked 6 years, 1 month ago Elizabete Silva 41 -
4
votes3
answers4047
viewsA: How to count and sum the amount of a certain "factor" in the observations (lines) of a data.frame?
Dear, would like to get the amount of "yes" (factor) on each line of a data.frame, as follows. Would anyone know what arguments I would have to use to do this with "mutate"? I tried several ways and…
-
4
votes2
answers171
viewsIdentify cases with multiple conditions in multiple columns in R
I have a dataframe with 20 students and I need to identify the students who attended stage 43 for two years or more. aluno <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,…
-
4
votes1
answer48
viewsMean of repeated lines
People, I have a data.frame as follows Gene 12h 10d 6w Slc39a10 1.52 -6.72 -1.84 Slc39a10 1.52 -6.72 -1.84 Mfsd6 -0.15 0.672 0.26 Mfsd6 -2.55 -54.53 -23.75 Hecw2 2.13 2.71 1.92 Hecw2 -7.30 -4.34…
-
4
votes2
answers4592
viewsHow do you turn a comma number into an R?
I have a csv file, saved via Excel (using ";" as column separator). When I import it into the R the numbers that are in the 0.00 format are as factor and comma. Ex: "123,45" When making the…
-
4
votes2
answers121
viewscalculate a probability function in R
Good afternoon. It’s my first intervention in the stack, I’m a beginner in the R, and my doubts are quite basic. I need to generate a sample of 1000 observations of a distribution function W. W is a…
-
4
votes1
answer90
viewsHow to read txt file with multi-dimensional datasets?
am with a dataset file composed of multiple dimensions in a single txt. For example, 2 3 #dimensao do primeiro dataset 1 2 3 4 5 6 4 4 #dimensao do segundo dataset 1 2 3 4 5 6 7 8 9 10 11 12 13 14…
rasked 6 years ago Wagner Jorge 1,377