Questions tagged [dplyr]

0 votes
0 replies
How do you create a new object and sort it by year, name and event? [duplicate]
I want to sort a data.frame by multiple columns. For example, with the data.frame below I would like to sort by column z (descending) then by col...
asked 1 month ago
0 votes
1 replies
dplyr grouping help, how to select a value from another column based on vale of another, if empty replace with N/A
I have a dataframe with the following columns userid: unique value for an user transactionId : unique value for the transaction (an user can...
asked 1 month ago
0 votes
2 replies
How to add to each column of dataframe value from named vector?
I've got a dataframe df. df <- data.frame(c(4,4,4,4,4,4), c(0,0,0,0,0,0)) colnames(df) <- c("a", "b") > df a b 1 4 0 2...
asked 1 month ago
1 votes
1 replies
What exactly is dplyr doing with filter() in case of multiple conditions?
E.g., library(dplyr) df <- data.frame(a = c(1,2,3,4,1),b = c(21,28,35,42,49)) df[(df$a != 1 & df$b != 49), ] df[!(df$a == 1 & df$b ==...
asked 1 month ago
1 votes
1 replies
SomersDelta: Error in as.table.default(x) : cannot coerce to a tabl in R
data example sommer=structure(list(tub = c(1L, 2L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 2L, 1L, 0L, 0L, 1L, 0L, 2L, 1L, 1L, 0L, 0L, 1L, 0L, 0L,...
asked 1 month ago
0 votes
1 replies
Tidyeval in a function with dplyr and ggplot2
So I create the name with :=, but I want to use it in ggplot2 as y which does not seem to work. library(tidyverse) date_group_plot_line <- f...
asked 1 month ago
1 votes
1 replies
How to calculate a proportions based on group by
I am trying to calculate consecutive proportions of the target feature. Data Set df <- data.frame(ID = c(11, 11, 11, 11, 11, 11, 11, 11, 11,...
asked 1 month ago
0 votes
1 replies
How to loop through numbers in dplyr
I have written a query that gives the number of false positives based on a percentage (A). I want to work out how many false positives different...
asked 1 month ago
1 votes
1 replies
Select rows with maximum value within each group in R [duplicate]
This question already has an answer here: How to select the row with the maximum value in each group...
asked 1 month ago
1 votes
2 replies
How to use fct_relevel with mutate_at syntax
I want to relevel the factors in a dataset, however I'm really struggling with the fct_relevel syntax and using it with mutate_at. I get a series...
asked 1 month ago
1 votes
1 replies
Calculate the differences between one row and the rest of the data per group
I have a data.table with three id groups. The first group (batch1) has fixed dx and varied dy. The 2nd group (batch1) and 3rd group (batch2) have...
asked 1 month ago
0 votes
1 replies
Table transformation with dplyr
I have a table called df. This table contains three columns (Code,Description and Rate). #CODE df<-data.frame( Code=c("01","0101","0101...
asked 1 month ago
2 votes
2 replies
r merge and create a dataframe based on time constraint
I have a dataset with two columns, ID and Start_Date as shown below ID Start_Date 19 2016-11-24 19 2016-11-26 3C...
asked 1 month ago
4 votes
2 replies
How to add rows with time periods inbetween given time period?
I have a data set with time periods, that may overlap, showing me if somebody was present (example_df). I want to get a data set that splits a la...
asked 1 month ago
1 votes
0 replies
dplyr grouping help, how to select a value from another column based on the min value of another [duplicate]
I have the following data: Name <- c("Sam", "Sarah", "Jim", "Fred", "James", "Sally", "Andrew", "John", "Mairin", "Kate", "Sasha", "Ray", "Ed...
asked 1 month ago
2 votes
2 replies
Find the average of a given set of numbers where the length of the set varies [duplicate]
This question already has an answer here: Calculate the mean by group 3 answers...
asked 1 month ago
0 votes
0 replies
Unfiltering in R to mutate a variable in a data frame
I have a data set of open-answer responses in a survey. I have a set of topics that I want to assign to these open answer responses according to...
asked 1 month ago
-1 votes
0 replies
stepwise remove edges in igraph
I have a large network in R. I use igraph to plot and analyze the graph. Now I want to compute the shortest path distances and the edge betweenne...
asked 1 month ago
2 votes
2 replies
How to collapse rows with same identifier and retain non-empty column values?
I have a table that (after some initial processing) has multiple rows with the same main identifier but with different column values (either 0 or...
asked 1 month ago
2 votes
2 replies
Add “%” to a dataframe of column percentages in R
I have a dataframe of percentages. I want to add a "%" at the end of each cell so that I can export/display them properly. It looks something lik...
asked 1 month ago
1 votes
1 replies
Recursive rolling average in R
Starting with the following: library(tidyverse) library(lubridate) df <- tibble( date = seq.Date(ymd("2018-01-01"), by = "month", length.o...
asked 1 month ago
0 votes
2 replies
Generate distribution based on mean and sd multiple times for different groups
I have a dataframe composed of a grouping variable, mean, and sd. I'd like to generate a number of means (eg., 10) for each group based on their...
asked 1 month ago
0 votes
0 replies
Creating Grouped Dataframe with dplyr
I have a dataframe that was put together from 6 other data frames using dplyr's "bind_rows" command. This worked nicely in terms of merging the c...
asked 1 month ago
1 votes
1 replies
Reshape several hour columns into key and value
I have a dataframe like this ID <- c("A","A","A","A","A","A","B","B","B","B","B","B") Day <- c("Mon","Mon","Mon","Fri","Fri","Fri","Tue",...
asked 1 month ago
2 votes
1 replies
dplyr group evaluation while simultaneously evaluating single items
library(tidyverse) df <- tibble(`Roman Numeral` = c(rep("I", 3), rep("II", 3)), Letter = c("A", "B", "C", "D", "E", "F"),...
asked 1 month ago