All Questions
36,879
questions
0
votes
1
answer
22
views
dplyr: count unique values [duplicate]
I have a data:
df <- data.frame(strain = 1:6, sample = c("a24", "a24", "a24", "a26", "a26", "a27"), region = c(rep("ny", 3), ...
0
votes
4
answers
37
views
Error when using bind_rows where one data frame has a column of type <hash>
I want to bind rows from two different data frames where one data frame contains a column of hash values whereas the second data frame doesn't contain this column.
library(tidyverse)
library(openssl)
...
0
votes
0
answers
27
views
Duplicated points in ggplot2 animation [closed]
I'm trying to do a visualization which is animated.
Problem: my points show duplicated regardless that I put the transition_time parameter to show the points every year.
Inside aes function I also ...
0
votes
0
answers
58
views
Complex lon/lat format manipulation
I originally developed a model to work with a df as df1_ref. Now, I found more data I need in a different format as df2.
df1_ref:
id country point_id lon lat value_A
...
0
votes
6
answers
49
views
Create a new column with averages for time intervals
I have a dataset that begins in year 1988 and ends in year 2020. I want to create averages for certain time intervals. For example, 5 years: 1988-1992, 1993-1997 and so on. But I want a new column ...
0
votes
1
answer
37
views
R index, filter then match on multiple criteria. Easy in excel, not so in r
I want to extract the 'untreated control' value for each variable and weed_type. In excel is easy to lookup the filter the value in the row and return the "untreated_contol" result for that ...
0
votes
0
answers
34
views
find value from dfa in dfb$col1 and report corresponding value in dfb$col2
I have two large dfs:
lookup_val <-c(30911003,23284867,31383855)
other_dat <-c(D,E,G)
dfa <- data.frame(lookup_val,other_dat)
dfb <- data.frame(returnme = c(100,200,300,400,500),
...
2
votes
1
answer
33
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:
...
2
votes
3
answers
52
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....
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 ...
0
votes
3
answers
28
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,...
3
votes
5
answers
75
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 ...
2
votes
4
answers
95
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("...
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 ...
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 ...