Posts by Tomás Barcellos • 5,562 points
126 posts
-
3
votes1
answer943
viewsA: Error in [.data.frame`(attr, , Region) : Undefined Columns Selected
The error is occurring because the column ID_2 does not exist in the object BRmap, as the error message is stating. When reading the file downloaded from the page indicated, we can verify that none…
ranswered Tomás Barcellos 5,562 -
6
votes1
answer301
viewsA: Example of Tidytext utility
The tidytext is a package that seeks to instrumentalize text analysis in a general way and therefore has 1001 utilities (and the most important of them can be found in the main vignette of the…
ranswered Tomás Barcellos 5,562 -
2
votes1
answer160
viewsA: How do I get R to repeat a request?
Try to get The following solution is neither efficient nor elegant, but does what you asked. lyrics2 <- function(x, type, key) { # Tenta pegar dados res <- try(lyrics(x, type = type, key =…
ranswered Tomás Barcellos 5,562 -
1
votes1
answer592
viewsA: Lines with alternate colors for a category variable ggplot
Initial data texto <- 'Animal Time Consumo 5 1 2.53396 5 2 2.32906 5 3 2.94379 5 4 3.36162 6 1 2.89082 6 2 2.53898 6 3 2.97881 6 4 3.03876 7 1 2.81885 7 2 2.73889 7 3 2.67891 7 4 2.87885' Consumo…
-
6
votes2
answers605
viewsA: What are the main functions for creating a minimum reproducible example in R?
The basis of a good reproducible question is that it should be possible for the your problem¹ appears as a problem for those who will try to understand it and solve it. Broad lines So that we can…
ranswered Tomás Barcellos 5,562 -
5
votes3
answers121
viewsA: How to create groups of 3 words in a text of random size?
Using the package tidytext, it is possible to solve your problem like this: frase %>% tidytext::unnest_tokens(output = ngram, input = texto, token = 'ngrams', n = 3) # A tibble: 7 x 2 id ngram…
ranswered Tomás Barcellos 5,562 -
5
votes1
answer758
viewsA: Grab URL table from R
As commented by @Marcusnunes, it is possible to do this extraction using the rvest: library(rvest) URL <- "http://globoesporte.globo.com/futebol/brasileirao-serie-a/" tabelas <- read_html(URL)…
-
2
votes1
answer82
viewsA: List all states in Node JS and Mongo
The problem is that its function is returning undefined. This is because its function returns a variable which is the result of console.log(). No need to create a new variable in the penultimate…
-
2
votes1
answer274
viewsA: Automatically identify points of influence in a regression
In fact, the function autoplot.lm package ggfortify there is no rule to mark these points. As can be seen here, she just takes the number passed to the argument label.n (which by default is 3) and…
-
6
votes2
answers396
viewsQ: Why are loops slow in R? How to avoid them?
It is very common to hear (or read) that loops are not efficient in Rand should be avoided (at this link or another link or even in this). And proving this statement is simple: numeros <-…
-
3
votes2
answers62
viewsA: Merge two series (zoo) of the same variable making the intersection and filling
The idea was basically to create an adaptation of the function rbind.zoo(). It checks which contiguous indices are not present in a or b, creates a new object zoo only with these indices and values…
ranswered Tomás Barcellos 5,562 -
3
votes1
answer70
viewsA: Include javascript in Shiny
Solution Below is a minimum and reproducible example of the solution. I switched your base to mtcars and the option targets to 1. library(DT) library(shiny) shinyApp(ui =…
-
3
votes2
answers206
viewsA: Scatter charts fixing a response variable
My approach was to take the name of the variables and pass them on ggplot as text within double brackets [[. colunas <- names(iris) resposta <- colunas[1] # escolhe variável resposta colunas…
-
6
votes2
answers604
viewsA: PDF to text organizing columns
The @José response is great for the page in question. But try using this algorithm on page 2 or 10 and you’ll see that things get a little out of hand. This is because not all columns have the same…
-
3
votes2
answers135
viewsA: Webscrape Scoring for Welfare
Using the packages stringr and rvest the question can be solved thus: library(rvest) library(stringr) url <- 'http://infograficos.estadao.com.br/especiais/placar/votacao/economia/?id=GLwN7vXR3W'…
-
2
votes2
answers751
viewsA: Error reading file: Error in scan line 6 Did not have 63 Elements
With the limitations we have to answer pointed out by @Marcus Nunes, I advise you to use the function fread() package data.table. The great advantage in this case is that you do not need to inform…
ranswered Tomás Barcellos 5,562 -
4
votes2
answers1839
viewsA: Column chart stacked in R
Since the ggplot2 2.2.0 there is also the geom_col() which is a shortcut to geom_bar(stat = "identity"). In this case, the syntax for the graph using the df of @Cinelli would: ggplot(df, aes(x =…
ranswered Tomás Barcellos 5,562 -
3
votes1
answer108
viewsQ: What’s new on R3.3.3?
R-core team launched on 03/06/2017 version 3.3.3 of R. Since then, some packages are releasing messages like this: package name_do_package was built under R version 3.3.3 What’s new in the R 3.3.3?…
rasked Tomás Barcellos 5,562 -
6
votes1
answer708
viewsQ: In R, when does a vector become "Too long"?
When trying to create an infinite vector (1:Inf) I received the following message: Error in 1:Inf : result would be Too long a vector However, when the vector does not know in memory the message is…
-
4
votes1
answer290
viewsA: problems with the agricultural package
In the fourth line of error the R is stating that you do not own the package coda, how @Guilherme Lima noticed. This problem can be solved by asking for the install.packages() download the…
ranswered Tomás Barcellos 5,562 -
4
votes2
answers256
viewsA: Sort the k highest results using dplyr
The dplyr makes use of chaining and pipe Operator (%>%) to improve the reading of the code and make it more succinct. In addition, it also has the function arrange() to sort the results. res1…
-
4
votes1
answer66
viewsQ: Why does rvest break when processing an empty file?
When trying to process the contents of an empty file the package rvest locks and closes the RStudio. Follows small reproduction of the problem: tf <- tempfile() file.create(tf) html_erro <-…
-
2
votes1
answer328
viewsA: Word cloud Shiny R
Your code has many problems. Below is a generic solution to the problem you described in the question: interactivity of the word cloud. As you reported no problems with reading the data I isolated…
-
6
votes2
answers272
viewsQ: In R, what is the best way to select sets of internal lists within a list of lists?
I have a list of lists like the one below: lista <- list(num = list(1:10, 11:20, 21:30), chr = list(letters[1:13], letters[14:26], LETTERS[1:13])) I’d like to turn it into a data.frame, but for…
-
2
votes2
answers272
viewsA: In R, what is the best way to select sets of internal lists within a list of lists?
pegar_elem <- function(x, vetor){ xx <- x for (i in seq_along(xx)) { xx[[i]] <- xx[[i]][vetor] } return(xx) } lista2 <- lapply(lista, pegar_elem, 1:10) as.data.frame(sapply(lista2,…
-
3
votes1
answer64
viewsQ: Is it possible to train a model when I only have one of the mapped classes?
I have a large dataset (~ 1,700,000) that I would like to sort. I also have a sample not so small (~ 8,000) classified as one of these classes (say, condition A), but I have none (zero) of the other…
machine-learningasked Tomás Barcellos 5,562