Most voted "dplyr" questions
dplyr is an R package dedicated to data manipulation.
Learn more…124 questions
Sort by count of
-
2
votes2
answers88
viewsSelect first with conditional
I am starting in R, and I have a data frame similar to this one below: x <- data.frame(cod_produto = c(1,1,1,2,2,2), valordia = c(0,0,150.23,110.98,18.65,0), data =…
-
2
votes1
answer61
viewsAdd order of records according to date and id
In R, I have the following data: id date 2380 10/30/12 2380 10/31/12 2380 11/1/12 2380 11/2/12 20103 10/30/12 20103 12/31/12 And I want to add a column with the order of the records according to…
-
2
votes2
answers79
viewsJoin for unequal records in R
I have two data frames called employees and employees. nome.empregado <- c('Renato', 'Miguel', 'Paulo', 'Patrícia', 'Inês', 'Saulo', 'Diego', 'Maria', 'Jose', 'Julia', 'Tiago') idade <- c(30,…
-
2
votes1
answer79
viewsFiltering a data.frame based on multiple variables
I have a data.frame with 9 variables from X1 to X9. The values of these variables are double. I need to filter the lines of this data.frame that contain (Xi,Xj,Xk) == (5.2,6.3,7.1) for example. I…
-
2
votes2
answers46
viewsMultiple Moving Medium Columns
I would like to create several columns derived from the column x. These columns should receive moving averages of 2, 5... periods. I tried to do the creation with dplyr::mutate, but it didn’t work.…
-
2
votes1
answer71
viewsHow does the `dplyr::n()` function know that it is not being called from the global environment?
When calling the function dplyr::n() 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…
-
2
votes1
answer842
viewsHow to summarize data in R?
I have a sample of shopping data and would like to know how many purchases had per user in total. dput to assist response: structure(list(USUARIO = c(931053L, 276977L, 354508L, 909717L, 69758L,…
-
2
votes1
answer541
viewsNames exchanged in a column: How to replace values in a column by keeping the rest of`data.frame` constant?
I imported a spreadsheet where two observations came exchanged and the rest was correctly filled. My problem can be demonstrated with the example below: the values assigned to the individual…
-
2
votes1
answer371
views -
2
votes1
answer71
viewsHow to order by class and by descending order?
Suppose the following database: set.seed(1) df_1 <- data.frame(x = replicate(n = 3, expr = sample(x = 1:3, size = 10, replace = TRUE))) By the way, with the package dplyr I tried to:…
-
2
votes1
answer44
viewsHow to use which.max in a long-format dataframe?
I have a DF in long format and tested the following code: library(tidycovid19) # Pacote do GitHub - https://github.com/joachim-gassen/tidycovid19 library(tidyverse) updates <-…
-
2
votes1
answer190
viewsLine operations of a Dataframe in R
I started using R recently. I would like to subtract corresponding lines from a Dataframe: The numbers in the ID column are fixed, but the data in the VALUE column is not. The idea would be to…
-
2
votes2
answers81
viewsHow to join more than two dataframes in R?
I have a list of 12 DF's that I need to put together in a single DF. The structure of all is equal, only differing the name of the second column, so the basic structure is: Column 1 is the date and…
-
2
votes1
answer58
viewsProblems with sum() function inside summarise using plyr and tidyverse!
Hello, good afternoon! I’m finding it difficult to use tidyverse, to perform a stacking function + summarise(soma=sum(value)) + pop =…
-
2
votes1
answer79
viewsCalculate percentage with dplyr::add_count
how it would be possible to calculate percentages with the dplyr::add_count()? To calculate with the dplyr::count() is very simple, as follows: library(tidyverse) dt <- Titanic dt %>%…
-
2
votes0
answers46
views -
2
votes0
answers46
viewsHow to group data in R?
I wonder if it has any function in the R that makes it possible to make a kind of "grouping" of the data. For example, a way to get this spreadsheet to return something like: Codigo Grupo Qtde Total…
-
2
votes1
answer245
viewsRelative Frequency Table - R / R Studio (% Daily Sales Determined Date/Product)
I have tried in every way to write a code that creates a relative frequency table, but I could not. I have a dataframe with the following variables: RANGE_DIAS: Interval of days between order date…
-
2
votes1
answer26
viewsHow to make a filter based on a condition?
I have a date.frame with two columns (CLASSWK and IND) and I’d like to apply a filter based on one condition, but I’m unable to do that. I have a column CLASSWK, that I only want to keep values that…
-
1
votes1
answer206
viewsClustering in the R
Guys, I need to Clusterize this database and then make the prediction.... I wonder, how could I make the substitution in the right way in this case ? Which type of Clusterization would fit best? I’m…
-
1
votes1
answer1848
viewsSelect part of Text in R
I would like to filter specific elements of a line, similar to the Excel filter. I have the following example: NOME VALOR LEITO 1 10 LEITO 2 - HPP 20 LEITO 3 - HPP 30 LEITO 4 40 I need to filter, in…
-
1
votes1
answer241
viewsError in View : invalid caption argument
I was working on the following script: library(tidyverse) library(dplyr) library(readxl) cirurgia <- read_excel("C:/Users/Agnes/Desktop/Coisas com…
-
1
votes1
answer49
viewsCommand to describe table data
Hello, I have a database and would like to know which field names through a command in R. What is the best way to proceed? I tried to use describe() but failed.
-
1
votes1
answer29
viewsWrong result when averaging per group
I am very beginner in R and am working on a large data.frame (approx 300000 data) that follows the example below: Identification Dates TEMP_Celcius 1 LONNIE POOL FIELD WEAVERVILLE 2014-01-01 13.0 2…
-
1
votes2
answers1675
viewsPercentage Frequency in R with dplyr
I wanted to use the dplyr package to calculate the Relative Frequency by group. I have a database like the first three columns below and I would like the last column to be the answer variable: CNPJ…
-
1
votes1
answer114
viewsHow to filter data by a text pattern in R
I have a database with data of Brazilian cities and states, I would like to filter only the states, all follow a pattern of having a "br_states_" before the name of the state. I tried to use the…
-
1
votes0
answers32
viewsIs there any functional difference between bind_rows (dplyr) and rbind.Fill (plyr) in R?
I would like to know if using one function instead of another there would be some differential in relation to the final dataframe to be produced. There were situations I tried to accomplish…
-
1
votes2
answers133
viewsIndicator on R with more than one condition with duplicate values
Suppose there is a basis 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…
-
1
votes1
answer78
viewsHow to replace lost data frame values with the average of each column in R?
I have this table: tabela<-data.frame(v1 = c(1,NA,3,5,4), v2 =c(NA,NA,1,2,4), v3 = c(6,5,4,7,NA)) I need the lost values of each column to receive the average values of that column. How to do…
-
1
votes1
answer95
viewsHow to take the variation with respect to the number of days of the date difference in R
I have a table in csv with 5 information, two with dates, two with prices, and one with the difference between dates. I have date 1 fixed on a date and date 2 varying. For example: 10/01/2018 >…
-
1
votes1
answer35
viewsTake previous values of a variable if the current value is 0 with a condition using dplyr in R
I have a database as follows: CNPJ data dataquebra alto 2222 201603 201711 s 2222 201511 0 s 2222 201702 201711 s 2222 201704 201711 s 3333 201601 201711 s 3333 201509 0 s 3333 201512 0 s 3333…
-
1
votes2
answers42
viewsGraph error in R: "invalid color name"
I’m working with the data set starwars, package dplyr. My goal is to create a chart with this data, where the independent variable is the height of the characters, and the dependent is their body…
-
1
votes1
answer55
viewsQuantitative position
I need to calculate the percentage of days that are in a certain range of values in the analyzed column (values are in percentage) in relation to the total quantity of days for that month. Initially…
-
1
votes1
answer23
viewsR language - Column separation
I have the two columns below and I need to separate them so that the digits are in other columns. The idea is to have at the end 4 columns with names of teams and score. Two columns of df2 type…
-
1
votes1
answer243
viewsHow to use filter_functions?
I try to use the functions filter_ (all, at, if), but unsuccessfully, mainly for strings. Consider the data set below: set.seed(1234) data_1 <- data.frame( a = c(paste('group', 1:6, sep = '_')),…
-
1
votes1
answer47
viewsHow to consolidate data set with dplyr?
Hello, I have a data set sinan18 that contains information about food outbreaks in Brazil. Formatting the original table - which is huge with dplyr, I arrived at the following result: >…
-
1
votes3
answers100
viewsHow to generate graphics from a file using a loop in R?
I would like from an archive, which in the case of public safety indicators of Rio de Janeiro, generate charts for each year of the database, showing the progress of these indicators over the…
-
1
votes1
answer44
viewsIf_else and Filter
I’m trying to give a filter: library(tidyverse) library(lubridate) filter(indicesBrutos, if_else(day(NomDataIn) != 1, filter(Mes >= NomDataIn-30, Mes <= CMData)), filter(Mes >= NomDataIn,…
-
1
votes1
answer60
viewsHow to create numerical samples based on multiple conditions on multiple vectors?
Given the following data frame: df <- tibble::tribble( ~pass_id, ~km_ini, ~km_fin, 1L, 0.89, 2.39, 2L, 1.53, 3.03, 3L, 21.9, 23.4, 4L, 23.4, 24.9, 5L, 24, 25.5, 6L, 25.9, 27.4, 7L, 36.7, 38.2,…
-
1
votes1
answer655
viewsReorder the columns of a bar chart and its caption
When processing and plotting data in R using tidyverse, it by default leaves the chart bar order in the original column factor order: library(tidyverse) mpg$trans <- as.factor(mpg$trans) mpg…
-
1
votes0
answers91
viewsRstudio - Update and add new data
Hello, I’m looking for IBGE data (library("sidrar")), df <- get_sidra (api = "/t/1846/n1/all/v/all/p/all/c11255/90707/d/v585%200") #Selecionando as colunas que me interessa df1 <-…
-
1
votes4
answers150
viewsCalculate percentage of an item in a group per year in R
I have a DF 14-column: item, grupo and years 2010 to 2021. I need to know the percentage of each item within the grupo to which he belongs. I tried to use a group_by with the summarise, but since I…
-
1
votes1
answer42
viewsIs it possible to multiply a variable of type "factor"?
I’m working with the following database: Qualis. I import this database using the rio::import() and write to the object "df". And I load library(dplyr) Upshot: library(dplyr)…
-
1
votes1
answer15
viewsTransformation of data frames into binaries in R
I’m doing a class exercise, but I believe you’re doing it the hard way and I’d like to know if there’s an easier way. This is the matrix I need to work on. The final matrix needs to have the matrix…
-
1
votes2
answers60
viewsAdd multiple selects in a single dataset
I have the dataset below and I do a consolidation of the categories Mk_cap, Exports and Money_supply, but each of these grids has a different Unit. df <-…
-
1
votes1
answer53
viewsIdentify the ID that has value at least one column for all rows
I have a data.frame with columns: cnpj, name, year, rop, des, Cax, pcld. I need to identify the cnpj that possess the value "1" in at least one of the columns rope, des, Cax and pcld for all years.…
-
1
votes1
answer37
viewslooping with dplyr in R
I’ve been looking for a solution to a question for days. I intend to create a repeating structure that allows to save a table for each class according to the code below, filtering and saving…
-
1
votes2
answers43
viewsLeft_join returning dataframe with more lines than the original
I have a date.frame with IBGE census data and a column called IND and I have another date.frame with a column IND and another column NEW_IND. The column NEW_IND contains the new codes for the…
-
0
votes1
answer459
viewsError loading dplyr package to R studio
I’m having trouble loading the dplyr package, when I insert library (dplyr) for this message: Attaching package: ?dplyr' The following Objects are Masked from ːpackage:Stats': filter, lag The…
dplyrasked 5 years, 11 months ago Sara Cristina 1 -
0
votes0
answers80
viewsCreate a mobile ranking based on a 252-day window
I have a time series of implied volatility index (retivol) in daily data. Sample of 9 years. I want to create a 20-percentile mobile ranking based on a 252-day mobile window t and compare the date t…