Questions tagged as 'dplyr'

2
answers

Indicator in R conditioned to variables with duplicate values

Suppose there is a base with two variables as follows: Município IF RIOBOM Cooperativa RIOBOM Cooperativa ABADIA Múltiplo ABADIA Múltiplo ABADIA Cooperativa ABADIA Banco DOURADOS Banco DOURADOS Múltiplo DOURADOS Banco DOURADOS...
asked by 17.11.2017 / 14:44
2
answers

In R, Using dplyr, create a new array

Suppose I have the following database >data zona candidato votos 1 A 100 1 B 20 2 A 30 2 B 15 I want, using dplry, the following array >nova zona votos_...
asked by 13.10.2014 / 23:11
1
answer

Subtract rows from one group in a data frame by another group

Assuming the following example: set.seed(1234) df=data.frame(grupo=rep(c("A1","A1.2","C","D"), 3), ano=c(rep(2007,4),rep(2008,4),rep(2009,4)), valor1=sample.int(100,12), valor2=sample(20,12), stringsAsFactors = F...
asked by 20.11.2018 / 19:38
2
answers

How to group data by an id in R

I have the following database: id x 1 2 1 3 2 3 3 3 3 3 3 3 I wanted to create a new database without repeating the value of the field id , to solve this I can average the values of field x tha...
asked by 12.04.2015 / 19:19
1
answer

R - How to create a delayed variable (lag) conditioned to the individual?

I need to delay a variable from my db ( dCoopCred ). However, it can not mix the delay of two individuals (% with%). I would like CNPJ to be LAG_Result_ant_desp in t-1 (previous period). Example: structure(list(CNPJ = c(...
asked by 15.06.2018 / 01:34
1
answer

How do I execute the str_detect (stringr) function for more than one variable at a time?

I want to filter my database based on two variables: via and city . This filter, however, is done by means of case particles present in these two variables. For example, I want to analyze who took the first route ( 1via ) and...
asked by 16.10.2018 / 04:23
1
answer

Problem in organizing a dataframe with tidyr in R

I have this dataframe and I need to organize it so that the unique dates are the first column and the columns are the shares of bovespa with their values being their respective prices: df<-structure(list(data = structure(c(1L, 1L, 1L, 1L, 1...
asked by 26.09.2018 / 23:34
1
answer

How to group information in a data frame from missing data?

I need to exclude empty df rows from a 30-year time series, with three daily measurements for each variable. I already used the subset(x, ...) function that solves part of the problem. However, in some cases there is no recorded measureme...
asked by 27.03.2018 / 15:14
1
answer

How does the 'dplyr :: n ()' function know that it is not being called from the global environment?

When calling the dplyr::n() function in the global environment, an error occurs. n() # Error: This function should not be called directly This error makes sense and I was curious to see how it was implemented. n # function () # { #...
asked by 12.12.2018 / 20:00
1
answer

execute .GlobalEnv function in parallel processing

I need to run a function that is in .GlobalEnv in a parallel processing using the multidplyr package. Using a simple example and no parallel processing works as expected: library(dplyr) library(purrr) library(multidplyr) data.frame(x = 1:1...
asked by 21.02.2017 / 19:24