Skip to main content

Questions tagged [dplyr]

Use this tag for questions relating to functions from the dplyr package, such as group_by, summarize, filter, and select.

2 votes
1 answer
30 views

Coalescing two `POINT` columns gives a list-column instead of another `POINT` column

I have two tibbles, each with a geometry column. I want to merge those and make a sort of coalesce() but if I combine ifelse() with st_is_empty() I end up with a list column instead of a POINT column: ...
bretauv's user avatar
  • 8,333
2 votes
3 answers
47 views

Custom function with dplyr::summarise with conditions

I want to create a function named ratio_function that does the same as the following code: data = data %>% group_by(ID) %>% summarise(sum_ratio = sum(surface[category == "A"], na....
Maxime Buron's user avatar
0 votes
2 answers
33 views

How can I merge specific dates into a date range in R

I am trying to integrate information on newspaper closures into a dataset of municipal elections in various provinces. The municipal elections data frame looks very much like this. Each province holds ...
spindoctor's user avatar
  • 1,837
0 votes
3 answers
26 views

Using 'slice_max()' in for loop

I'm trying to create new dataframes with the top three values for each column across a dataframe. probUnweighted <- data.frame( Sample1 = c(0.9, 0.2, 0.03, 0.1, 0.5, 0.09), Sample2 = c(0.045, 0.11,...
Chris Stantis's user avatar
3 votes
5 answers
71 views

Order columns based on suffix with dplyr and stringr

I have a dataframe that has columns that are separated out by suffix see ex_df. Each time I run the code there may be varying column amounts based on database entries so I am trying to find a way to ...
JasminL0p3z's user avatar
2 votes
4 answers
93 views

Conditional mutate based on order of variables

I have vectors that index the events A, B, C. Each event occurs at least once but can occur multiple times. For example: Sequence 1: c("A", "B", "C") Sequence 2: c("...
gregor-fausto's user avatar
0 votes
2 answers
31 views

Create labelled column from numeric and character columns

Having two columns, one with numeric values and other with text labels that correspond exactly with the numeric values, how can I create a labelled column (<dbl+lbl>), like the ones imported by ...
Bastián Olea Herrera's user avatar
0 votes
1 answer
25 views

Re_order based on month and date while ignoring year in R

Lubridate doesn't have a month-date col type it appears and I would like to make a histogram across several years that focuses just on the month and day while ignoring the year. But when it comes time ...
Jeff Henderson's user avatar
1 vote
2 answers
45 views

data frame breakdown by year, rounding up by duration of each period

I have a data frame of county executives and the first and last years they served. I am running a panel study with county-year as the unit of analysis. The date range is 2000 to 2009. I will like to ...
YouLocalRUser's user avatar
0 votes
4 answers
65 views

Substring replacement in data frame, based on a look-up table [closed]

As input, I've got a large data frame in R with lists of strings of different lengths, referring to certain codes - like this: glt.code glt.phylogeny 1 adha1238 adha1238 ...
Moehrengulasch's user avatar
2 votes
3 answers
74 views

R how to create a new dataframe with column values calculated from three other dataframes

I'm new to R and struggling to create a new dataframe where the values for multiple columns are created using values from columns with the same names from three other dataframes with the same ...
user26403036's user avatar
2 votes
4 answers
108 views

data.table vs dplyr: apply function returning changing column names over groups

I want to apply a function (ratefunc()) to a grouped data frame which returns changing column names dependent on the result: library(data.table) library(dplyr) dt <- data.table:::data.table( ...
Cevior's user avatar
  • 119
2 votes
3 answers
69 views

Complete and fill missing rows with groups of uneven length

I have a dataframe of county executives and the year they were inaugurated. I am running a panel study with county-year as the unit of analysis. The date range is 2000 to 2004. I will like to expand ...
YouLocalRUser's user avatar
0 votes
1 answer
33 views

Remove string from column across group of rows in another column

I would like to remove a string from one column across a group of rows in another column. In the below reprex, I would like to remove the string in snippet from the string in text in any row in the ...
maia-sh's user avatar
  • 557
1 vote
2 answers
23 views

How to select specific columns across multiple dataframes in R and then bind them into one data.frame?

I am trying to select or subset multiple data frames with different number of columns. They all contain the same columns of interest, so I am trying to make them all contain the same columns so I can ...
Victor Shin's user avatar

15 30 50 per page
1
2 3 4 5
2482