purrr Questions

8

Solved

I often find questions where people have somehow ended up with an unnamed list of unnamed character vectors and they want to bind them row-wise into a data.frame. Here is an example: library(magri...
Radman asked 5/5, 2020 at 13:58

7

Solved

Using reduce(bind_cols), the list elements of same dimension may be combined. However, I would like to know how to combine only same dimension (may be specified dimesion in some way) elements from ...
Sacks asked 8/6, 2021 at 13:33

1

Solved

I want to run some modelling on each group of variables a and b. The problem is that nest() doesn't include the grouping variables which are needed by the model. expand.grid(a = LETTERS[1:3], b = L...
Kickapoo asked 4/6, 2021 at 11:22

2

Solved

I searched for ??"~" but this only points me to rlang::env_bind (presumably, %<~%) and base::~. Within RStudio, how can I find Purrr's ~'s documentation? For example, if I forgot how t...
Laic asked 21/5, 2021 at 19:47

4

Solved

I have multiple dataframes/tibbles with the same exact structure, but different contents. Their name is the only way I can differentiate them. The objective is to merge them all together into one d...
Joey asked 28/7, 2017 at 13:9

4

Solved

I have two data frames, one is survey data (data.csv) and another one is label data (label.csv). Here is the sample data (My original data has about 150 variables) #sample data df <- tibble::tr...
Keelson asked 12/5, 2021 at 13:0

2

I am having problems with this ifelse sentence inside map function: df<-list(mtcars,mtcars) All I want to do is to organize each dataframe of this list this way:slice(x,c(n(),2:(n()-1),1)) map(...
Moldboard asked 28/4, 2021 at 23:21

5

Solved

This is a question for which I've written failsafes in my code before, but I'm wondering if there's something more straightforward that I've missed. I sometimes have 2 (or more) lists that contai...
Impuissant asked 22/4, 2019 at 17:41

1

Solved

May be this question termed as part-3 of this question. I know that arguments in lambda functions when used in tidyverse especially purrr functions are written as - . when there is only 1 argument...
Nitrogenous asked 15/4, 2021 at 10:18

2

Solved

I have been exploring the various application of using pmap function and its variations recently and I am particularly interested in using c(...) to pass all the arguments into. The following data ...
Inappetence asked 11/4, 2021 at 19:52

1

Solved

I have this data frame and I would like to solely use pmap function to filter only rows where all values are either negative or positive. I am looking for a concise way of doing this as I thought a...
Utgardloki asked 10/4, 2021 at 17:7

2

Solved

In base R I would do the following: d <- data.frame(a = 1:4, b = 4:1, c = 2:5) apply(d, 1, which.max) With dplyr I could do the following: library(dplyr) d %>% mutate(u = purrr::pmap_int(lis...
Grizzly asked 3/4, 2021 at 19:16

5

I have a data frame, the data frame is already sorted as needed, but now I will like to "slice it" in groups. This groups should have a max cumulative value of 10. When the cumulative value is > ...
Sigma asked 30/12, 2015 at 14:38

3

Solved

Please help me 1) Why does map_if not work within a list 2) Is there a way to make it work 3) If not, what are the alternatives Thanks in advance. library(dplyr) library(purrr) cyl <- spli...
Asbury asked 14/3, 2017 at 9:35

2

Solved

I am converting a nested list of a specific structure (required by an API) to JSON using toJSON() in jsonlite. However, I need the final JSON to not contain the outer square brackets (also required...
Sakhuja asked 9/5, 2019 at 6:5

2

Solved

I read the manual for using accumulate saying that it is a 2-argument function. I don't understand the given example: 1:5 %>% accumulate(`+`) #> [1] 1 3 6 10 15 If accumulate is a 2-argument...
Ammonal asked 7/2, 2021 at 4:20

1

Solved

A user defined function CollageImage <- function(path, country, strain, assay,subgroup) { img_out <- magick::image_read(path) %>% magick::image_trim() %>% magick::image_convert(form...
Ebon asked 1/2, 2021 at 18:48

1

Referring to the documentation for across() (https://dplyr.tidyverse.org/reference/across.html), you can specify the name returned from the dplyr verb using the .names argument. Viz iris %>% gr...
Gelderland asked 7/9, 2020 at 13:6

4

I did mtcars %>% by_row(sum) but got the message: by_row() is deprecated; please use a combination of: tidyr::nest(); dplyr::mutate(); purrr::map() My naive approach is this mtcars %>%...
Pricillaprick asked 14/4, 2017 at 18:54

1

I am trying to replace the NULL elements of the list below with NAs inside a map() before using rbindlist on the cleaned list: m = list(min = list(id = "min", val = NULL), max = list(id = "max",...
Burrill asked 28/2, 2019 at 23:50

3

Solved

I want to know the best way to iterate over rows of a data frame when the value of a variable at row n depends on the value of variable(s) at row n-1 and/or n-2. Ideally I would like to do this in ...
Refute asked 1/9, 2019 at 2:29

3

Solved

My data consist of an identifier (srdr_id), and a list column. dat <- structure(list(srdr_id = c("174136", "174258", "174684"), outcomes = list( structure(list(outcome_s = c("use_alcohol", "us...
Jordaens asked 13/5, 2019 at 23:0

3

Solved

I am using the map function of the purrr package in R which gives as output a list. Now I would like the output to be a named list based on the input. An example is given below. input <- c("a",...
Kutenai asked 12/5, 2017 at 10:13

4

Solved

This is my transaction data. It shows the transactions made from the accounts in from column to the accounts in to column with the date and the amount information data id from to date amount &lt...
Parasang asked 8/9, 2020 at 13:51

4

Solved

What is the purrr::map equivalent of: for (i in 1:4) { for (j in 1:6) { print(paste(i, j, sep = "-")) } } OR lapply(1:4, function(i) lapply(1:6, function(j) print(paste(i, j, sep = "-")...
Why asked 18/2, 2018 at 1:31

© 2022 - 2025 — McMap. All rights reserved.