Questions tagged as 'dplyr'

5
answers

How 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") regiao<-c("Norte","Sul","Leste","Norte","Sul","Norte","Leste","Sul") df<-data.frame(vendedor,regiao,vend...
asked by 27.02.2014 / 02:36
4
answers

Add rownames as column using dplyr

I would like to do something that is fairly simple using the common syntax of R, but using the dplyr package. The task is basically to add the row.names of a data.frame object as a column to that same object. Using mtc...
asked by 01.10.2014 / 20:11
3
answers

How to separate a string from a certain row in a data.frame and at the same time create more rows?

I have a data.frame with a column with strings of type "123-235-203". For example, the line:    string column1 column2   123-235-203 x and I want to separate this string, so that the line containing it will multiply preserving the va...
asked by 30.04.2015 / 02:00
1
answer

filter in dplyr using a categorical variable

Suppose I have the following dataset: set.seed(12) dados <- data.frame(grupos=rep(letters[1:5], 5), valores=rnorm(25)) head(dados) grupos valores 1 a -1.8323176 2 b -0.0560389 3 c 0.6692396 4 d 0.8067977 5 e...
asked by 08.06.2017 / 18:15
1
answer

Building new variables using dplyr

I have the following database Clientes.Dep..Gratuito.PCG Clientes.Dep..Gratuito Clientes.Dep..Não.Gratuito 0 0 0 0 0...
asked by 28.07.2017 / 15:59
1
answer

How to calculate percentage variation with 3 variables in R

I have the following data: library(sidrar) Tab1612SojaQde <-get_sidra(1612,variable = 214, period = c("last"=22), geo="State",classific = 'c81', category = list(2713)) head(Tab1612SojaQde) Unidade da Federação (Código) Unidade da Fe...
asked by 03.12.2018 / 21:05
2
answers

Rename the levels of a factor based on a data frame

Suppose I have the date frame iris , 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...
asked by 02.12.2017 / 20:11
2
answers

Sort the highest k results using dplyr

I can select the largest k results of a table in R. For example, if k equals 5, I get the following result: library(dplyr) library(ggplot2) top_n(mpg, 5, wt=displ) # A tibble: 5 × 11 manufacturer model displ year cyl tr...
asked by 08.12.2016 / 22:23
1
answer

Improvement of code

Good afternoon. I have the following data structure: structure(list(CIDADE = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), MES = c(1L, 2L...
asked by 24.07.2017 / 19:24
1
answer

Bar chart sorted using dplyr and ggplot2

I'd like to create a bar chart after counting the number of occurrences of categories in a dataset. Suppose my dataset is this below: dados <- structure(list(categorias = structure(c(5L, 4L, 5L, 3L, 1L, 2L, 5L, 3L, 1L, 1L, 4L, 4L, 1L, 5L,...
asked by 28.06.2017 / 18:46