All Questions
3,891
questions
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,...
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 ...
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 ...
1
vote
2
answers
42
views
Recode relationship matrices based on new subgrouping
Problem:
I have a survey dataset which includes intra-household relationships. I had to subdivide household into tax-unit, which means I need to redefine the relationship matrices based on the new tax-...
0
votes
1
answer
26
views
additional arguments to purrr:map don't work as expected
I'm using the purrr::map function to iterate over several columns and tidy the result. for a short example, I provide the following code:
library(tidymodels)
library(broom)
> penguins %>%
+ ...
2
votes
2
answers
83
views
How to create subgroups based on group relationship criteria
Context:
I have a dataframe of individual people grouped by household, which includes relationship parameters for each individual describing their relationship to every other individual in the ...
3
votes
4
answers
69
views
Joining lat/lon data frames by nearest distance
Let's say I have a regular latitude/longitude grid and data at irregular locations, like this:
grid = tidyr::crossing(lon = seq(0, 1, 0.25), lat = seq(0, 1, 0.25))
data = tibble::tibble(lon = runif(4),...
0
votes
1
answer
36
views
Sample all rows of N groups
I'm trying to find a way to sample N whole groups from a dataframe.
For example, if we had the below dataframe:
group value
1 a 1
2 a 2
3 a 3
4 b 4
5 b ...
0
votes
0
answers
44
views
What is the preferred / recommended rlang metaprogramming syntax to use on both sides of an assignment operator in the `dplyr::mutate()` function?
I have a question about an issue that's similar to this older question about the dplyr::filter() function, except that my example is a bit more complicated because dplyr::mutate() needs to process ...
0
votes
1
answer
23
views
Transforming value into row number
I am conducting some survival analysis and an attempting to turn my wide table into long format for analysis using dplyR. I want to turn the value of 'dead flies' into rows with a binary status for ...
0
votes
1
answer
46
views
Is there a way to pass a string as a variable/column name to my function and use in a call to mutate?
I have a dataframe with a column indicating choices (of a survey) as well as a column indicating the index of the choice made in each row. e.g.,
df <- tibble(
record_id = 1:9,
choices = c(rep(&...
2
votes
4
answers
63
views
How to obtain all the numeric variables in data frame and use in another function in R
the below example is to obtain the min value among 3 columns, we can use the pmin(V1, V2, V3).
if we have lots of columns, how to get the minimal value among all numeric variables especially using the ...
1
vote
1
answer
59
views
Conditional filtering of dataframe in R
I wonder how to dplyr::filter() my DATA to catch the rows for IDs whose Language value when 'Type!=5F' and when 'Type==5F' changes from other languages to "English"?
For example, ID==1 has ...
2
votes
2
answers
30
views
Wide format data by pasting two sets of variables into one in R
I've tried to wide-format my DATA into my Desired_output using:
pivot_wider(DATA, names_from = Year, values_from = c(Type, Language))
without success. Is there a way to achieve my Desired_output?
...
1
vote
1
answer
49
views
Is there an elegant way to handle changing number of rows within tidyverse?
In Tidyverse there are limitations concerning the row number resulting from some data processing. Most prominent, mutate expects that the row number equals to the original data set. For example, if we ...