purrr Questions
2
Solved
Let's say I have a tibble.
library(tidyverse)
tib <- as.tibble(list(record = c(1:10),
gender = as.factor(sample(c("M", "F"), 10, replace = TRUE)),
like_product = as.factor(sample(1:5, 10, ...
Agustinaah asked 22/3, 2018 at 16:52
2
Solved
Is there a way to automatically give names to the returned list given by purrr:map?
For example, I run code like this very often.
fn <- function(x) { paste0(x, "_") }
l <- map(LETTERS, fn)...
2
Solved
While playing around with the purrr package of the Tidyverse in R, I saw that the map() function returns a list.
library(tidyverse)
set.seed(123)
map(1:5, ~rnorm(3))
#> [[1]]
#> [1] -0.56047...
3
I am using furrr which is built on top of future.
I have a very simple question. I have a list of files, say list('/mydata/file1.csv.gz', '/mydata/file1.csv.gz') and I am processing them in parall...
Adelleadelpho asked 30/7, 2019 at 21:34
3
Solved
Alright, I'm waving my white flag.
I'm trying to compute a loess regression on my dataset.
I want loess to compute a different set of points that plots as a smooth line for each group.
The pro...
4
Solved
I have data like this:
example_df <- data.frame(
col1type1 =c(110:106),
col2type2 = c(-108:-104),
col3type1 = c(-109:-105),
col4type2 =c(110:106),
col5type1 =c(107:103),
col6type2 = c(-11...
5
Solved
Using the tidyverse a lot i often face the challenge of turning named vectors into a data.frame/tibble with the columns being the names of the vector.
What is the prefered/tidyversey way of doing t...
4
I'm trying to automatically calculate the mean score per row for multiple groups of columns.
E.g. a set of columns could represent items of different scales.
The columns are also systematically nam...
3
Solved
I often have the problem that R converts my one column data frames into character vectors, which I solve by using the drop=FALSE option.
However, there are some instances where I do not know how to...
3
I would like to use the accumulate function with two input vectors and the reduce2 function. The documentation for accumulate implies that two input vectors can be given and that accumulate can wor...
5
Solved
I'm doing something quite simple. Given a dataframe of start dates and end dates for specific periods I want to expand/create a full sequence for each period binned by week (with the factor for eac...
6
Solved
I feel like there is probably a better way to do this in tidyverse than a for-loop. Start with a standard tibble/dataframe, and make a list where the name of the list elements are the unique values...
1
Solved
My problem requires me to summarize data across multiple columns, but each column must be summarized by a multi-variate function of three other columns.
I have a data frame with hundreds of columns...
6
Solved
I want to use dplyr::coalesce to find the first non-missing value between pairs of variables in a dataframe containing multiple pairs of variable. The goal is to create a new dataframe with now onl...
3
Solved
I have a panel dataset at the country and year level, and I'd like to create a two new variables based on existing ones.
year
country
var1
var2
var3
var 4
mean_var1
relmean_var1
1910
GER
1
...
Southworth asked 24/11, 2021 at 13:9
1
Solved
My question is similar to this one, but the latter did not receive an answer I can work with. I am scraping thousands of urls with xml2::read_html. This works fine. But when I try and parse the res...
Tailrace asked 22/5, 2019 at 16:59
4
Solved
Some code:
mymtcars <- mtcars %>% head %>% rownames_to_column('model') %>% group_by(vs) %>% nest
mymtcars
vs data
<dbl> <list>
1 0 <tibble [3 × 11]>
2 1 <tib...
2
Solved
I have the following nasty, nested list
Edit: updated to include value_I_dont_want
mylist <- list(
list(
nested_1 = list(
nested_2 = list(
list( value_I_want = "a", value_I_dont_want = "f...
2
Solved
I have recently come across an interesting question of calculating a vector values using its penultimate value as .init argument plus an additional vector's current value. Here is the sample data s...
Tact asked 28/7, 2021 at 15:48
5
Solved
I'm trying to create "waves" of variables that represent repeated measures. Specifically, I'm trying to create consecutive variables that represent the mean values for variables 1 - 10, 1...
3
Solved
Been practicing with the mtcars dataset.
I created this graph with a linear model.
library(tidyverse)
library(tidymodels)
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_point() + geom_smooth...
Tarpley asked 13/7, 2021 at 0:6
3
Solved
I wish to have a fast way to deal with rowwise calculations where values of cells depend on values in previous rows of different columns, prefering vectorization over looping through individual row...
Eliathas asked 13/7, 2021 at 13:38
2
Solved
I am trying to generate values for over 7 variables across millions of observations and it's taking forever when I write a for loop to achieve this. Below is an example of what I am trying to achie...
6
Solved
I am looking for a way to make column names and dataframe names from a list of dataframes into a single dataframe. They have unequal length of columns. What's the best way to do this?
dlist <- l...
3
Solved
I have a list whose elements are integers and I would like to accumulate these elements if only they share at least one value. With regard to those elements that don't share any values with the res...
Matthewmatthews asked 14/6, 2021 at 13:8
© 2022 - 2024 — McMap. All rights reserved.