Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
81 views

I use the tidyverse suite to estimate 6 linear models as a function of empirical subgroups and different functional forms library(tidyverse) library(magrittr) library(marginaleffects) library(...
tomw's user avatar
  • 3,281
Best practices
1 vote
6 replies
81 views

I am working on a project that has some pretty heavy computations that I want to parallelize. I want to use purrr and mirai. I have a ton of functions defined that are used in the computations that ...
Honestiore's user avatar
4 votes
2 answers
103 views

If you want to call a function that returns multiple values on a column of a data.frame, and append these values as new columns to the data.frame, you can mutate(map()) |> unnest_wider(). If it's ...
mac's user avatar
  • 3,794
0 votes
1 answer
88 views

Taking the following data: library(tidyverse) df <- data.frame(id = c("a", "a", "a", "b", "b", "b"), x = c(NA, "...
deschen's user avatar
  • 11.6k
2 votes
2 answers
371 views

I was excited when I read about the latest update of purrr (1.1.0) with its in_parallel capabilities. I just happen to have a time-consuming data task that runs for several minutes, because: my data ...
deschen's user avatar
  • 11.6k
2 votes
2 answers
137 views

I have a simple list like library(tidyverse) library(openxlsx) mtcars |> group_split(cyl) And now I want to save each list as an Excel file to the folder specified in cyl like so: mtcars |> ...
deschen's user avatar
  • 11.6k
1 vote
1 answer
124 views

I want to remove passwords from several Excel files, so I specified a data frame with paths and passwords and then added some python code running with reticulate. When I pass that function to a for ...
deschen's user avatar
  • 11.6k
0 votes
1 answer
87 views

I like to call a command line utility from R and parallelise the tool by calling several copies of it in different folders. Each call can have quite different runtimes, so I'd like to do this in an ...
user3460194's user avatar
0 votes
2 answers
83 views

I tried to use 'map' to filter a list of dataset. how can I extract the name of dataframe, which is 'YYY' in my code. library(dplyr) library(purrr) df1 <- data.frame(var1=seq(1:10), var2=seq(1:10),...
Stataq's user avatar
  • 2,451
0 votes
1 answer
79 views

I have a deeply nested list that I am trying to extract into a simple df. Sample List df <- tibble::tribble( ~division, ~id, ...
Jazzmatazz's user avatar
1 vote
3 answers
155 views

I have this small function and want to apply it to a dataset using purrr::map(). It does what I expect it to do, but after the output it also prints a list of NULL, which I don't want. I would like to ...
Claudio's user avatar
  • 1,615
1 vote
1 answer
95 views

I'm working with the Jira Native API to bring in dashboard data to R for rectangularizing. The max results that can be returned each call is 100. I'm working with a small dashboard atm but am thinking ...
PhDavey's user avatar
  • 438
0 votes
0 answers
42 views

In the process of learning this part: vectorised functions The current version of purrr has deprecated the invoke_map function, what is the problem with this latter code? I am really confused. sim <...
Breeze's user avatar
  • 584
1 vote
1 answer
86 views

I have an issue when working with httr2::last_response() and purrr::possibly() and I can't quite figure out how to resolve it, as other posts involving either httr2 or purrr::possibly doesn't really ...
PeRiKo's user avatar
  • 13
1 vote
4 answers
127 views

I'm trying to select specific items in a list that are not in the top level, and everything I can think of doesn't work the way I would expect. Here is a dummy list where what I do NOT want is item &...
shirewoman2's user avatar
  • 1,960
-1 votes
1 answer
64 views

Based on this post for gglikert. There the group1 column had 2 levels and group2 has 3. Now if i implement it with 3 levels in group1 and 4 levels in group2 library(ggstats) library(dplyr) library(...
Homer Jay Simpson's user avatar
0 votes
1 answer
46 views

I have a bunch of dataframes that contain individual-level person data for complex survey weight adjusted survey data at a state level. Say one for each state: df_1, df_2, ..., df_50 I have a ...
abrar's user avatar
  • 153
9 votes
2 answers
1k views

Below is a reproducible example with a test dataframe: dat<- structure(list(A = c(1.3, 1.5, 1.6, 1.2, 1.1, 1.2), B = c(0.25, 0.21, 0.21, 0.15, 0.26, 0.17)), ...
M.O's user avatar
  • 521
2 votes
3 answers
98 views

This question is similar to this question, but the difference in this case is to suppress data row-wise. The suppression is done in each row by replacing any value less than 6 in each row with -1 ...
William's user avatar
  • 412
2 votes
4 answers
135 views

I have a huge data. I like to suppress data across multiple columns by replacing any value less than 6 in each column with -1 such that if in a column, there is only one suppressed value, I want to ...
William's user avatar
  • 412
1 vote
2 answers
70 views

Given a data frame such as the following: dat <- data.frame( plotType = c("RP", "FP"), turbType = c("3;8", "5;7"), turbSize = c(2.4, "3.6;...
user1658170's user avatar
1 vote
0 answers
51 views

The following is an example of a question that has been asked several times in the past, but I have not seen a fully satisfactory answer. I would like to know if newer strategies have been developed, ...
Stephen's user avatar
  • 507
4 votes
3 answers
133 views

I have a list that contains web-traffic details. In the process of rectangling the lists, I'd like to append a value to each vector in the named sublists which is the actual name of the sublist vector....
DeduciveR's user avatar
  • 1,712
3 votes
1 answer
72 views

In my data, the strings in one column (TCU_clean) are substrings in another column (TCU_clean_collpsd); in a third column (w_c7_collpsd), which is the key target column, the same substrings appear but ...
Chris Ruehlemann's user avatar
4 votes
2 answers
104 views

I am working with a series of data.frames in a list, where each round adds a new year and drops the last year, as shown in the picture below: Here is the R code for the minimal reproducible example: ...
Grasshopper_NZ's user avatar
0 votes
1 answer
58 views

I have a code that works if I am using LM but not if I am using a GAM. I guess the that for whatever reason LM looks inside object for the variable and GAM just looks at the names of the object but I ...
adrianmnc's user avatar
0 votes
4 answers
98 views

I have the following input table: input <- structure( list(individual = c(1, 2, 3, 4), age = c(20, 34, 29, 30), earnings_2020 = c(0, 0, 1, 0),...
Chloe's user avatar
  • 1
2 votes
1 answer
77 views

I have modified glue using purrr::partial and it works fine except when I try to using it together with purrr::map. There are multiple workaround but I'm confused on why this does not work? library(...
MLEN's user avatar
  • 2,579
2 votes
2 answers
80 views

I have a dataset in which one of the variables is states and the other is districts (that are located in each state), and the remaining are numerical variables. There are 32 states, and 712 districts ...
Prasanna's user avatar
1 vote
0 answers
112 views

The following minimal example illustrates it: dfr <- data.frame(x=1:1e6, y=1:1e6) f <- function(x,y) x+y # faster system.time( for (i in 1:50) purrr::pmap(dfr, \(x,y) x+y) ) # slower system....
arb's user avatar
  • 75
0 votes
1 answer
133 views

Map statements are just awesome, but their inputs often feel needlessly redundant. For example, in the block below, it seems silly to have to re-list the variables I've already requested from the ...
Aegis's user avatar
  • 210
1 vote
1 answer
89 views

I've got a large dataset and want to apply a custom function over each of the columns. I've written the function and it works when applied as a one-off on one column of the target dataset. However, ...
r.bot's user avatar
  • 5,434
2 votes
1 answer
101 views

I am wondering how to convert this example code to purrr style by using the walk() function instead? library(cli) n <- 10 cli_alert_info("About to start downloads of {n} file{?s}") i &...
Grasshopper_NZ's user avatar
1 vote
1 answer
246 views

I am trying to understand the behavior of purrr::map() vs purrr::pmap() for the following use case. I was expecting the same result, but looks like purrr::map() iterates only once through the list. # ...
Srivathsan Seshadri's user avatar
1 vote
1 answer
62 views

I have multiple lists which look like this: list(structure(list(mail = c("[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "yo@yo....
Alejandro Carrera's user avatar
2 votes
2 answers
121 views

The following toy data has 5 variables, X1 to X5. set.seed(123) df <- data.frame(matrix(rnorm(500), 100, 5)) I want to perform specific operations on specific variables, using a named list of ...
user18894435's user avatar
4 votes
4 answers
123 views

I’m trying to run the following code: xx <- 1:12 yy <- 1:3 map2(xx, yy, ~ .x / .y) However, I encountered an error. I assumed that map2() would automatically recycle the shorter vector (i.e., ...
Jenny Chung's user avatar
1 vote
3 answers
125 views

How can I use reduce function together with lag to obtain the summation but at the same time ignore missing values? a <- data.frame( b = c(1, 2, NA, 3, 4, 5)) a %>% mutate(addition = reduce(map(...
user2360397's user avatar
1 vote
1 answer
71 views

I am trying to learn some basic purrr. Take this toy example - how do I essentially append "rank" to the current variable name as it's created using map_df? library(tidyverse) # generate ...
LucaS's user avatar
  • 1,335
1 vote
0 answers
119 views

I'm am trying to become more familiar with purrr rather than using for loops. I have some toy data (from a real problem) where I have several clinical visit values in one cell. I need to split these ...
LucaS's user avatar
  • 1,335
1 vote
0 answers
71 views

Hi so I make a lot of graphs and was wondering if I was doing it in a fast, efficient way. I need to make visualizations commonly that are commonly ~2000 pages long (one for each unit of analysis) I ...
paxton's user avatar
  • 91
1 vote
2 answers
154 views

I am working with the unvotes package, the objective is "Using purrr functionality, find out which three countries on average agreed with the US the most from the year 2000 on". I first ...
joyjoylili's user avatar
3 votes
1 answer
103 views

outer_func uses tidy evaluation for col_rfs and dflt_flag, i.e. it is possible to do col_rfs = dplyr::starts_with("col"). library(magrittr) outer_func <- function(dat, col_rfs, dflt_flag)...
PalimPalim's user avatar
  • 3,068
2 votes
4 answers
130 views

I have a vector x and a function f. I need to generate the matrix whose first column is v, second column is f(v), and so on up to the final column f^k(v). In a functional language I could use an ...
Mohan's user avatar
  • 9,223
0 votes
1 answer
73 views

I need to apply a custom function to a set of columns in a dataset and return a list. I can do this in lapply() but I am trying to work with purrr. Toy data. Three factor variables df <- data.frame(...
llewmills's user avatar
  • 3,414
2 votes
1 answer
87 views

I have two types of models (GAM and beta regression) that I am running for my data and I am using a lapply function to iterate over multiple variables. I am encountering an error when trying to export ...
DaniH's user avatar
  • 75
0 votes
1 answer
52 views

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 %>% + ...
user23485480's user avatar
5 votes
5 answers
154 views

I would like to convert a list like this into a tibble. lst <- list( "A"=list( "Category"="A", "Team"=c("x"), "City"="...
mindlessgreen's user avatar
0 votes
1 answer
63 views

Here is my code : plan(multisession,workers=detectCores()-2) future_map_dfr(.x= Liste_model[1:2],.f = summaryModel, df = DF_MODEL_TRAIN, df_test = DF_MODEL_TEST, df_global = DF_MODEL_GLOBAL, .id = &...
Rgrvkfer's user avatar
  • 417
6 votes
2 answers
139 views

I have a reprex as follows: library(dplyr) library(purrr) df1 <- data.frame( col1 = 1:5, col2 = 6:10 ) df2 <- df1 %>% mutate(col3 = 1:5) ls <- list( a = list(df1 = df1), b = ...
sactyr's user avatar
  • 439

1
2 3 4 5
72