Posts by bbiasi • 774 points
36 posts
-
1
votes1
answer40
viewsA: How to identify if one observation is in the same group as another?
There are several ways to arrive at the expected result. Here I present how to do this with the package job dplyr. Quantity of cnpj per municipality: library(dplyr) df <- empresas %>%…
-
2
votes1
answer106
viewsA: Predict plot for adjusted Gamlss model
Following the example of book "Flexible Regression and Smoothing Using GAMLSS in R", the Plot of the predicted values, adjusted, can be done by following the example below. library(gamlss)…
-
1
votes1
answer116
viewsA: How to use summarise?
Test this: # glimpse(CCEE) CCEE <- CCEE %>% dplyr::mutate_if(is.character, as.factor) %>% dplyr::mutate(atividade = stringr::str_to_title(atividade), data = lubridate::as_date(data), value…
-
2
votes1
answer892
viewsA: How to save a ggplot chart without losing quality to Word and Power Point?
Sometimes plotting figures from the R is not a simple task. Patience is required for checking the best fit. There are even those who skip the final step of adjustment of Plot for the use of some…
-
7
votes3
answers146
viewsA: Print more variable text
Using the paste. lenesson <- 10 paste("Seu número é", lenesson) Output. [1] "Your number is 10"
-
4
votes1
answer620
viewsA: How to set a decimal display pattern in R?
It is possible to accomplish this for the Chunk and to inline. See in the example below: the real value, value with modification for inline and the modification to the Chunk. The code below is in…
-
2
votes1
answer70
viewsA: How to plot a time series graph with ggridges?
I identified some situations for Plot and lack of coherence for the df. I found it interesting to adjust the date to check if the organization of df really portrayed reality. And in proceeding with…
-
4
votes3
answers1493
viewsA: How to number lines of a data.frame in R?
There are several ways to perform this action. I leave here a contribution with examples using "base" and packet-aided R commands. With resident commands in the R: As already shown by…
-
2
votes2
answers552
viewsA: R - Selecting elements of a data frame with a column that has the same name as a global variable with`dplyr`
With the aid of dplyr it is also possible to use the operator !! or the function UQ. library(dplyr) df %>% filter(x == UQ(x)) Or df %>% filter(x == !!(x)) This operation "indicates to R" that…
-
1
votes2
answers450
viewsA: Bar graph with ggplot2
To create charts of this type it is possible to use new packages that can be interpreted as an extension, such as ggpubr using ancillary functions based on ggplot2. library(tidyr) dados <-…
-
0
votes1
answer70
viewsA: Chart with captions overlaid in R [without using ggplot2
library(RColorBrewer) #cores cor = brewer.pal(12, "BuPu") gen = c(1, 130, 2, 31, 1 ) labs_g = c( "Desconhecido" , "Genótipo 1", "Genótipo 2", "Genótipo 3", "Genótipo 4") val_g = c("0,5% (1)", "77,3…
-
0
votes1
answer72
viewsA: Create filter to select data without duplicity, from rules applied to variables
Note that the name line 18 and the name line 12 have the same characteristics, but different results for the filter you provided as an example, this can create bias to your goal. Anyway, realize…
-
0
votes1
answer44
viewsA: How to write multiple string (names) in R?
You actually want to create a vector?! nome <- c("a", "b", "c", "d")
-
2
votes1
answer29
viewsA: How to choose the best in each year of a column in R?
Using the package dplyr or data.table it is possible to do this. Creating data: # dados ficticios set.seed(1) df <- data.frame(ano = rep(2015:2018, each = 5), nome = rep(letters[1:4], 5),…
-
1
votes1
answer43
viewsA: Average column value within a table with R
Using the summarise_all package dplyr. library(dplyr) set.seed(1) x <- c(15,12,8,9,5,6,1,2) df <- data.frame(x, y = rnorm(length(x)), w = rnorm(length(x))) df %>% dplyr::summarise_all(mean)…
-
1
votes4
answers1763
viewsA: How to know which is the largest variable of a vector in R?
If you already have the vector built (like the vetor), and have only the need to find the highest value scalar, I suggest using the for with ifelse to transform its numerical vector (vetor) in a…
-
1
votes3
answers193
viewsA: Conditional formatting on line R
You can do it with the package dplyr. df <- data.frame(var1 = c(rep(NA, 5), 1, 1, 1, rep(NA, 4), 1), var2 = c(rep(NA, 3), 19, 13, rep(NA, 8)), var3 = c(rep(NA, 8), 10, 8, 7, 5, NA))…
-
2
votes2
answers5241
viewsA: How to order Ascending and descending in R?
It is also possible to perform this action with the package data.table. # df exemplo set.seed(1) LL <- c(sample(1:10, size = 2, replace = T), sample(1:10, size = 5, replace = T)) base <-…
-
0
votes1
answer276
viewsA: How to save an Excel spreadsheet from R without blank lines?
You should initially clean gave data frame to later be able to export it. There are different ways to do this, here I will present 3. Using the package dplyr library(dplyr) nome_seu_dataframe <-…
-
0
votes2
answers14389
viewsA: How to filter a data frame?
I also provide an example from the package data.table using the @Carlos Cinelli example data. library(data.table) set.seed(1) df <- data.frame(valor = rnorm(100), categoria = rep(c("AB", "AC"),…
-
0
votes3
answers21039
viewsA: How do I exclude a set of specific lines, listed in a vector, from a data frame in R?
For a situation where more manpower is needed for data handling, and expected good yield, use of the package data.table can be of great help. I leave here a brief example using the Toy date by…
-
1
votes4
answers8289
viewsA: How to put different graphics of ggplot2, separately but on the same screen?
In addition to the packages mentioned, there are also packages cowplot, ggpubr, patchwork and egg. In the case presented here, all return the same Plot. library(ggplot2) p1 <- ggplot(mtcars,…
-
2
votes4
answers8280
viewsA: How to put the regression line on a graph?
It is also possible to work with interactive graphic if necessary. For this, the package tip highcharter. set.seed(1) x <- rnorm(100) y <- rnorm(100) + 2*x +10 dados <- data.frame(x = x, y…
-
0
votes6
answers31940
viewsA: How to remove a data.frame column in R?
With the data.table package it is also possible. set.seed(1) dados <- data.frame(y=rnorm(100), x= rnorm(100), z=rnorm(100), w=rnorm(100)) library(data.table) df <-…
-
1
votes3
answers3287
viewsA: How to put the regression equation on a graph?
It is also possible to automate these output with the function stat_poly_eq package ggpmisc. library(ggplot2) library(ggpmisc) set.seed(1) x <- rnorm(100) y <- rnorm(100) + 2*x +10 dados <-…
-
2
votes1
answer25
viewsA: problems with Cycle for
For this situation there is a simpler solution, just use the base::replace. df1 <- data.frame(High = c(0.51, 0.92, 0.78), Low = c(0.43, 0.28, 0.22), Middle = c(0.22, 0.21, 0.9), nomes =…
-
1
votes2
answers283
viewsA: x-axis for time series in ggplot
Since there is no reproducible example, I am mounting the answer based on a dataset fictional. library(ggplot2) set.seed(1) n <- data.frame(z = seq(1990, 2018, 4), x = c(rnorm(n = 4, mean = 7.5,…
-
1
votes1
answer51
viewsA: How to add or eliminate scatter points on a graph mechanically?
Maybe the gatepoints package will be useful to you. library(gatepoints) set.seed(1) df <- data.frame(x = c(rnorm(n = 100, mean = 4, sd = 2), rnorm(n = 10, mean = 10, sd = 10), rnorm(n = 5, mean =…
-
4
votes3
answers1276
viewsA: A: Creating a new variable using if and Else
To create variables I suggest using dplyr package with function employment mutate. Following are examples. library(dplyr) base <- data.frame(x = c(rep("076", 4), "840", "442",rep("076", 4))) base…
-
2
votes1
answer39
viewsA: Import data with spaces within fields from a txt to R
Importing . txt file from tab separated data file in Excel. clipboard <- read.delim("arquivo") # # arquivo = Endereço da pasta no computador + /nome do arquivo.txt clipboard <-…
-
0
votes1
answer177
viewsA: Plot of points Axis X ggplot2 space between numbers
You should adjust the scale of your Plot. whereas p be its object of Plot generated with the ggplot2, just increase the adjustment of breaks on the scale x. p + scale_x_continuous(breaks = seq(0,…
-
2
votes2
answers82
viewsA: What books do you recommend to study on data analysis in R?
In addition to the material commented by Guilherme Parreira, recommend the book Introduction to Data Mining with R Applications, by Leandro Augusto Silva. This book is very good for this stage, it…
-
0
votes1
answer89
viewsA: Help with variable prediction with machine Learning and unbalanced classes in R(Caret)
Unfortunately I don’t have a minimum score to comment on, so... From what I understand the goal is just to predict the size of a leaf, which can be a tree or a grass, correct? If yes, a regression…
-
1
votes1
answer164
viewsA: How to increase the bars of a chart in R?
I don’t quite understand the logic of groups=médias.Trat and unfortunately, I still don’t have a minimum score to comment on questions. I leave here my brief contribution and indication for use of…
-
0
votes1
answer81
viewsA: Sunrise and sunset in R
library(suncalc) library(dplyr) lon <- -46.6821862 lat <- -23.5977319 timezone <- base::grep("Brazil", base::OlsonNames(), value = T) # tz de SP = timezone[3] # Sys.Date() = data de hoje df…
-
1
votes1
answer87
viewsA: How to use the `dplyr::rowwise` function with more than one variable?
In method 1 I understood that it is returning the total sum value of all objects. In method 2 there is something analogous. set.seed(1) df_1 <- data.frame( x = replicate(4, runif(30, 20, 100)), y…