Posts by Guilherme Duarte • 918 points
16 posts
-
1
votes2
answers213
viewsA: Reorder bars in ggplot2 according to one of the fill variables (Fill)
Use the fct_reorder function of the forcats package for this. df %>% mutate(equipamento, = fct_reorder(equipamento, perc)) %>% ggplot(aes(x=equipamento ,y=perc, fill=situacao),…
-
3
votes1
answer230
viewsA: Scrape of MTE mediating system
The question is on how to perform this specific scraping on R. Note that the form for Tprequester requires a list, which we can implement as vector. In R, I would do so: body <- list( nrCnpj="",…
-
11
votes2
answers32556
viewsQ: How to remove duplicate lines efficiently?
I’m normalizing a table here and found that there are duplicate lines. The way I chose to clear these lines is through the: CREATE TABLE tabela_nova AS ( SELECT DISTINCT * FROM tabela_antiga ); The…
-
2
votes1
answer282
viewsQ: How to change the format of a direct column in Mysql’s LOAD INFILE?
Hello, I have a table 'x', with the column Value, in DECIMAL, in a Mysql 9 database. It turns out I need to import data in csv. I do this using LOAD INFILE. In these Csvs, the value is in comma…
mysqlasked Guilherme Duarte 918 -
7
votes3
answers1163
viewsA: How to separate a string from a certain line of a data.frame and at the same time create more rows?
Hadley himself offers us the answer in the tidyr Vignette. library(tidyr) library(dplyr) df <- data.frame( x = 1:3, y = c("a", "d,e,f", "g,h"), stringsAsFactors = FALSE ) df %>% transform(y =…
-
9
votes3
answers1163
viewsQ: How 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…
-
5
votes2
answers274
viewsA: Is there a hash structure in R?
There may be a native solution, but an interesting solution is to use the "hash package". For example, library(hash) Using the hash() function to create the hash: h <- hash(c("carro", "caminhao",…
ranswered Guilherme Duarte 918 -
12
votes2
answers274
viewsQ: Is 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 Guilherme Duarte 918 -
2
votes1
answer222
viewsQ: Is it possible to modify a value of an array with assign() in R?
Suppose we have x <- "teste" You can assign another string to test using assign: assign(x, 1:5) Thus: test [1] 1 2 3 4 5 Would it be possible for me to modify some of the values of the vector…
rasked Guilherme Duarte 918 -
4
votes1
answer503
viewsA: How to replace a series of whitespace with just one in a string in R?
Two possible solutions: gsub("\\s+", " ", x) and gsub("[[:space:]]+", " ", x)
-
3
votes1
answer503
viewsQ: How to replace a series of whitespace with just one in a string in R?
How do I replace a series of blank spaces with just one, in R? For example, suppose we have a string: x <- " non non non non" I want to make the content of x: "non non non non non non non non".…
-
4
votes2
answers823
viewsQ: Dplyr and gsub: how to replace parts of one column with another
I have the following data-frame: xis <- data.frame(x1=c("**alo.123", "**alo.132", "**alo.199"), x2=c("sp", "mg", "rj"), x3=c(NA)) I would like to create a new column, using gsub as follows: x3[1]…
-
2
votes3
answers3977
viewsA: Organize data in Excel to open as table in R?
Check the tabs in the file . csv, opening it in text mode. In function read.csv, you must set the Sep parameter. For a table with the "&" character, as separator: you should use banco1 <-…
-
2
votes1
answer5140
viewsQ: Loading Rdata files from the file directory itself . R
How to load Rdata files that are in the same directory as the file . R, in Rstudio? Here, for example, is the line: load('teste.RData') When loaded, it returns... Erro em readChar(con, 5L, useBytes…
-
8
votes4
answers16549
viewsA: How to include columns in a data.frame?
Beyond the: df$z <- c(1,2) Other simple ways to add just one column are: df["z"] <- c(1,2) df[["z"]] <- c(1,2) df[,"z"] <- c(1,2) Similarly, you can remove it with: df$z <- NULL And…
ranswered Guilherme Duarte 918 -
4
votes1
answer147
viewsQ: How to import data from clibboard to a data-frame in R
One of the advantages of using spreadsheet is that we can import data from the Clipboard. Is there any way to do it in R?
rasked Guilherme Duarte 918