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
-
32
votes4
answers5405
viewsStrategies to analyze very large databases in R (that do not fit in RAM)
Suppose I have a huge database that doesn’t fit in RAM. What strategies to analyze this database in R, since I cannot load it entirely into memory? PS: The question isn’t just about how to get R to…
-
22
votes5
answers12797
viewsHow to consolidate (aggregate or group) the values in a database?
Suppose I have the following database vendas<-c(100,140,200,300,20,1000,200,3000) vendedor<-c("A","B","A","B","C","C","D","A")…
-
19
votes1
answer2245
viewsR is an object-oriented language?
A theoretical doubt of who uses (and who does not use) the r is whether this programming language is (or not) object-oriented. I’ve seen comments on Soen that said the following: r is not object…
-
18
votes3
answers4338
viewsWhat is the "line break" in a Regex?
The language I use is R. And, as the theory of Regular Expressions suggests, each language deals differently with line breaks (\n). Consider the following string: text_1 <- c('Olá, meu nome é…
-
17
votes7
answers9711
viewsRemove accents
I need to know how to remove the accents of a die in a column. # Eu tentei > library(stringr) > a <- dados$Municipio[2] > a [1] "Arapeí" > str_replace_all(a, "[í]", "i") [1]…
rasked 9 years, 10 months ago Lucas Guimarães 171 -
16
votes2
answers4769
viewsApply, sapply, mapply, lapply, vapply,rapply, tapply, replicate, Aggregate, by and correlates in R. When and how to use?
What is the difference between the functions apply, sapply, mapply, lapply, vapply, rapply, tapply, replicate, aggregate, by and correlates in the R? When and how to use each of them? There are…
-
16
votes2
answers7712
viewsSearch for values in one data.frame and add to another (R)
I have 2 data.frames, the first is a data.frame that contains stock data and a column with a unique identifier (column "ISIN"), as an example below: Teste=data.frame(matrix(runif(20), nrow=5,…
-
16
votes1
answer250
viewsDifference between the greedy ?? and *quantifiers?
I have these strings: x <- c('ondasffasf', 'ondassn\nlld', 'ondas', 'ond', 'ndasss', 'das') And this code with ??: library(stringr) str_extract(x, regex('ondas??')) [1] "onda" "onda" "onda" NA NA…
-
15
votes5
answers1048
viewsWhat is the use of knowing how to debug a code in R?
According to the theory, debugging can be defined as the art and science of correcting unexpected problems in your code. What is the usefulness (for a data analyst) of knowing thresh a code? What…
-
15
votes1
answer704
viewsWhat is and what is an anonymous function in R?
What is an anonymous function? And why can it be called função lambda? What is the usefulness of an anonymous function in language R? Where it can be applied (for example, it can be applied in…
-
14
votes4
answers5814
viewsHow to read microdata from ENEM in R?
The INEP (Instituto Nacional de Estudos e Pesquisas Educacionais Anísio Teixeira) makes available for download the microdata of ENEM (and others) from this link. These microdata are the ENEM’s raw…
-
14
votes1
answer261
viewsWhat is the usefulness of lexical and dynamic scopes in R?
In the chapter 6 of the book Advanced R there are definitions of lexical and dynamic scopes. However, I did not understand the usefulness of knowing these concepts in r. Thus, the usefulness of the…
-
13
votes2
answers10996
viewsError while converting numbers. How to convert factors to numbers?
In the following example: dados <- data.frame(x=c("11", "10", "20", "15"), y=c("25", "30", "35", "40")) dados x y 1 11 25 2 10 30 3 20 35 4 15 40 When trying to transform the variable x number,…
-
13
votes2
answers1065
viewsObject orientation in R: S3, S4 and Reference Class
R has, among others, three main forms of object orientation: S3; S4; and, Reference Classes. What are the main differences between the three methods? And how to implement them (preferably provide a…
-
13
votes4
answers1143
viewsAdd rownames as column using dplyr
I would like to do something that is quite simple using the common R syntax, but using the package dplyr. The task is basically to add the row.names of an object data.frame as column on that same…
-
13
votes3
answers1955
viewsPre-process large text files in R
I am writing a script, which I will make public, to open the micro-data of RAIS (dehydrated, available here) in R using Monetdb. However the bank does not accept vígula (,) as decimal separator.…
-
13
votes1
answer678
viewsCalling C functions from R
I need to optimize some functions that are in the C language, but using the packages of genetic algorithms in R. Is there any way to call C functions in R? In Matlab I know that there is this…
-
13
votes1
answer1466
viewsHow to make a bubble chart, each filled in according to a ratio
I’m trying to make a chart like this on R: The graph is available on this link. I don’t need it to be dynamic like the link, but if it is, no problem. In it, each bubble is divided between the blue…
-
13
votes2
answers2429
viewsHow to recognize and change the encoding of Latin characters in R?
Is there any efficient way to recognize the encoding of texts downloaded from the internet? I made a scraping of any site (see code below) and I can’t find the correct encoding. In the META tag of…
-
13
votes1
answer323
viewsHow to convert a Shiny app, consisting of multiple files, into a playable example that can be shared in a question?
Problem Here at Stackoverflow in English there is guides and also questions whose theme are the reproducible examples. However there is nothing equivalent to the Shiny what can make life difficult…
-
12
votes4
answers1519
viewsWhy is 0.1 + 0.05 not equal to 0.15? What solutions can be used in R?
In the R: 0.1+0.05 == 0.15 [1] FALSE Why does this happen? How to get around the situation (functions and packages to handle floating points)? Editing: This other question already contains general…
-
12
votes1
answer2292
viewsHow to create objects (variables) with different names within a loop?
I want to generate different databases in a loop. In the example below would be 3 distinct databases with the following names: "data1", "data2", "data3". for (n in 1:3){ dados<-paste0("dados",n)…
-
12
votes2
answers274
viewsIs there a hash structure in R?
Is there any hash structure in R, similar to Python and javascript Dictionaries? This makes programming much easier.
rasked 9 years, 6 months ago Guilherme Duarte 918 -
12
votes4
answers1339
viewsEquivalent to Excel SOMASES, in R
I am deepening in R and looking for a function that is equivalent to the sums of excel. I have this following DF: Day.of.Week Hour Quantidade 5 21 5044 3 12 5024 1 11 4725 0 16 4643 1 15 4601 4 14…
rasked 8 years, 7 months ago Felipe Amaral Rodrigues 309 -
12
votes3
answers1460
viewsArea of intersection of two polygons
How to calculate the area of intersection between two polygons? For example: a = matrix(c(0 ,0 ,2 ,0 ,2 ,2 ,0 , 2, 0, 0), byrow = T, ncol = 2) b = matrix(c(.5, 0 ,1 , 1, 1.5, 0, .5, 0), ncol = 2,…
rasked 8 years, 5 months ago Wagner Jorge 1,377 -
12
votes1
answer996
viewsEstimate the Poisson - R distribution
I have a grafo and calculated the distribution of degrees and degree as follows: dd <- degree_distribution(graph) d <- degree(graph) From that, I cherished the Power Law, to see if my…
-
12
votes2
answers605
viewsWhat are the main functions for creating a minimum reproducible example in R?
What are the main functions to create a reproducible minimum example in r? More specifically, I would like the answers to address the following topics:: What are the functions to ensure that the…
rasked 6 years, 11 months ago Carlos Cinelli 16,826 -
12
votes1
answer572
viewsWhy should we scale/standardize values of variables and how to reverse this transformation?
When working with multivariable prediction algorithms I came across the function scale of the R, whose objective is to scale/standardize the values of the variables. I have no difficulty in using…
rasked 4 years, 10 months ago Izak Mandrak 1,059 -
11
votes2
answers355
viewsNegative variance in R? Floating point error propagation
Suppose the following formula to calculate the variance: variancia <- function(x) { n <- length(x) (1/(n^2-n))*(n*(sum(x^2))-(sum(x)^2)) } Note that it is equivalent to the function var in…
-
11
votes3
answers2755
viewsHow to assign the results of a function that returns a list of objects?
In R we can make a function return more than one object through a list. But how to assign these objects to two distinct variables? Example: f<-function(){ primeiro<-1:10 segundo<-11:21…
-
11
votes1
answer1619
viewsThe order function in R
I don’t understand what happens. Watch > x<-c(-2,4,-6,5,9,7) > x [1] -2 4 -6 5 9 7 > order(x) [1] 3 1 2 4 6 5 I don’t understand why vector x is not ordered. Note, when I give order(x)…
-
11
votes2
answers15918
viewsDelete lines containing NA in a data frame
I have a data frame and in the fourth column there are several NA cells. I would like to know how to delete all lines that have NA. I used this command but they keep showing up dataframe1 r <-…
-
11
votes1
answer266
viewsHow to create Needles chart in R?
I am trying to make a chart of Needles suggested in the Matter of Non-parametric Methods in the study of Histograms. I found a command called rug(), but it seems that the idea is not that.…
-
11
votes3
answers3977
viewsOrganize data in Excel to open as table in R?
I have a file with 50 observations and 3 variables in Excel file (.xlsx), and turned to .csv. I used banco1<- read.csv("teste1.csv") to create the table in R, however my 3 variables appear in the…
-
11
votes1
answer573
viewsDispersion graph with marginal histograms
I wonder if there is a way to make a chart similar to this in the R: It is possible to make a dispersion Plot and to the side or below, as it presents the image, place the histogram representing the…
-
11
votes2
answers930
viewsError "invalid input '.. 'in utf8towcs" with "read.csv"
I have a database on . csv that gathers posts from both Facebook and Twitter. For the reading of the bank in R, the code I have used is bancodedados <- read.csv("nomedobanco.csv", sep=";",…
-
11
votes1
answer347
viewsHow to get facebook share information with R?
I’d like to know how I can get information about Facebook post shares, such as user name and id and date and time of sharing. In the package RFacebook you can obtain the same information, but…
-
11
votes3
answers2014
viewsWeb scraping with R
I am trying to make a Web Scrapping of the following link: http://empresasdobrasil.com/empresas/alta-floresta-mt/ I want to access all categories and extract a data frame with the name of all…
-
11
votes2
answers2457
viewsHow to exclude element from a list in R
I have this list: x = list(1, 3, 5, 8, 13) How do I delete the second element?
rasked 8 years, 5 months ago Daniel Dutra 2,283 -
11
votes1
answer2490
viewsPattern recognition
I have hundreds of digital images of dogs and cats, I need to make an algorithm to recognize when the dog is and when the cat is. What steps should I take?
-
10
votes2
answers5010
viewsHow to correctly position the Abels in the barplot?
I am not able to correctly position the names in a barplot of R, because they are very extensive. My data is this way: The names end up appearing this way: fator_tecnologico_labels <- c(…
-
10
votes2
answers2443
viewsHow to smooth a curve in R
The goal is to get the smoothed chart from data frame. x <- c(1e-04, 0.0014, 0.018, 0.24, 3.2, 42, 560, 7500, 1e+05) y <- c(0, 7, 10, 7, 0, -7, -10, -7, 0) df <- data.frame(x, y) The curve…
-
9
votes4
answers8280
viewsHow to put the regression line on a graph?
Suppose a linear regression model like the following: set.seed(1) x <- rnorm(100) y <- rnorm(100) + 2*x +10 modelo <- lm(y~x) If I plot y against x, how do I include the regression line in…
-
9
votes3
answers1784
viewsHow to format a table (data.frame) with pdf publishing quality (latex) in R?
Suppose the following table: tabela <- structure(list(Sexo = structure(c(1L, 1L, 2L, 2L), .Label = c("Homem", "Mulher"), class = "factor"), Grupo = structure(c(1L, 2L, 1L, 2L), .Label = c("A",…
-
9
votes1
answer159
viewsHow to find a table by category with minimum observations?
Suppose you have the following data: a<-c(rep("agosto",3),rep("janeiro",4),rep("maio",6)) table(a) I want to know the month with the minimum of observations? With the function min(table(a)) the…
-
9
votes2
answers3449
viewsIn R, count words and enter a line break
Dear friends, good afternoon Suppose I have a vector the following way caption<- c("I really liked the performance", "I didn’t like the performance", "I neither liked nor disliked") I want to…
-
9
votes1
answer87
viewsRamdrive with video card ram
I use the R language for heavy matrix calculations. I’m using gpu for performance gain, which is fantastic indeed. However, I would like to take another step and dump the 2gb data matrix directly…
-
9
votes3
answers1163
viewsHow to separate a string from a certain line of a data.frame and at the same time create more rows?
I have a data.frame with a column with strings like "123-235-203". For example, the line: string column1 column2 123-235-203 x y I want to separate this string so that the row that contains it…
-
9
votes1
answer196
viewsRstudio: do not automatically load variables in Environment
Whenever I start Rstudio some variables appear in environment. Is there any way to remove them automatically without using the famous rm(list=ls())? Thank you!…
-
9
votes5
answers1065
viewsRemove duplicated names with regular expression
Suppose I have the following vector, with the names of presidents of the republic: presidentes <- c("da Fonseca, DeodoroDeodoro da Fonseca", "Peixoto, FlorianoFloriano Peixoto", "de Morais,…