purrr Questions
5
Solved
I have some archived Slack data that I am trying to get some of key message properties. I'd done this by stupidly flattening the entire list, getting a data.frame or tibble with lists nested in som...
2
Solved
I'd like to sample rows from a data frame by group. But here's the catch, I'd like to sample a different number of records based on data from another table. Here is my reproducible data:
df <- ...
2
Solved
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 = l...
4
Solved
Take this simple dataset and function (representative of more complex problems):
x <- data.frame(a = 1:3, b = 2:4)
mult <- function(a,b,n) (a + b) * n
Using base R's Map I could do this to...
3
Solved
I would like to mutate new columns onto a dataframe using a function where the inputs to the function come from a vector. Like this:
library(tidyverse)
# sessionInfo()
# R version 4.3.2 (2023-10-3...
4
Solved
I'm trying to do something that seems very simple, but I cannot figure it out. I have a tibble like so:
> df <- tibble::tribble(
~col_a, ~col_b,
1, "A",
2, "B",
3, &...
6
Seems like a basic question and perhaps I'm just missing something obvious ... but is there any way to pluck a sublist (with purrr)?
More specifically, here's an initial list:
l <- list(a = "fo...
3
Solved
How can I find the path of an element in a nested list without manually digging through a list in a View?
Here is an example that I can already deal with:
l1 <- list(x = list(a = "no_match&...
Defant asked 17/3 at 10:19
3
Solved
How to use purrr's map function to perform row-wise prop.tests and add results to the dataframe?
I'm trying to solve the following problem in R: I have a dataframe with two variables (number of successes, and number of total trials).
# A tibble: 4 x 2
Success N
<dbl> <dbl>
1 28....
4
Solved
Beginner in data manipulation in R, I struggle with multi-level nested lists.
Question: Is there a way to transform this dat0 3-levels list into the global dat1 dataframe below?
The new fulltext c...
Origen asked 19/12, 2023 at 18:1
3
Solved
Consider this simple example
mydf <- data_frame(regular_col = c(1,2),
normal_col = c('a','b'),
weird_col = list(list('hakuna', 'matata'),
list('squash', 'banana')))
> mydf
# A tibble: 2 ...
10
Solved
I have to following issue using R. In short I want to create multiple new columns in a data frame based on calculations of different column pairs in the data frame.
The data looks as follows:
df ...
5
I have a list structured this way:
x <- list(id = c("a", "b"),
value = c(1,2),
othervalue = c(3,4)
)
I need to transform the list to this structure like this:
y <- li...
Zygote asked 12/6, 2023 at 10:35
0
I have a function using nested map calls to process chunks (the inner map process a single chunk and the outer map runs through all chunks). Both processes are slow enough that it's useful to have ...
2
Solved
I am using map function from purrr library to apply segmented function (from segmented library) as follows:
library(purrr)
library(dplyr)
library(segmented)
# Data frame is nested to create list...
2
As part of a pipeline, I'd like to take a data frame or tibble and rename a subset of columns, specified by a vector of position indices, with the new column names as a function of their index rath...
3
Solved
Another seemingly easy task where purrr::map2 is giving me a hard time.
I have a list of data frames and I have a vector of column names. I now want to rename a certain column in each of the data f...
3
Solved
I have a dataframe (df1) and a list of dataframes (test) like below; I want to join df1 with each of the datafraems in test and populate a new column (X), while keeping all the other records intact...
1
Solved
Consider the following Rmarkdown document:
---
title: "Environments"
author: "Me"
date: "2023-01-13"
output: html_document
---
```{r setup}
library(glue)
library(purr...
Solfeggio asked 13/1, 2023 at 10:15
2
Maybe I'm missing something obvious but trying to flatten a list of named lists of named lists in R (may even be more nested) into eventually one flat list. purrr and rlist seem to have tools for t...
Hypothyroidism asked 13/3, 2018 at 9:22
4
Solved
Is there a way to map to any type with purrr::map
library(tidyverse)
library(lubridate)
df <- data_frame(id = c(1, 1, 1, 2, 2, 2),
val = c(1, 2, 3, 1, 2, 3),
date = ymd("2017-01-01") + day...
5
Solved
Is there any reason why I should use
map(<list-like-object>, function(x) <do stuff>)
instead of
lapply(<list-like-object>, function(x) <do stuff>)
the output should be...
6
How do I achieve row-wise iteration using purrr::map?
Here's how I'd do it with a standard row-wise apply.
df <- data.frame(a = 1:10, b = 11:20, c = 21:30)
lst_result <- apply(df, 1, func...
3
I am using the 'segmented' package to find break points in linear regressions in R
library(tidyverse)
library(segmented)
df <- data.frame(x = c(1:10), y = c(1,1,1,1,1,6:10))
lm_model <- lm(y...
5
Solved
I have a list with many levels. I want to only keep elements at the 1st level.
Example list:
my_list <-
list(
a.1 = "some text",
b.1 = NA,
c.1 = integer(0),
d.1 = "some text...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.