tidyselect Questions

2

Solved

This works as expected: library(dplyr) f <- function(x = c(am, vs)) mtcars %>% select({{x}}) How would I rewrite the function (let's call it f2) such that f2 selects only the first elem...
Upswing asked 6/9, 2024 at 11:57

3

Solved

I'm having this error when trying to attach package tidyselect and when trying to call tidyselect::any_function. The error happens in Rstudio or command line alike, in RStudio it is triggered as so...
Hamburg asked 3/9, 2018 at 13:12

3

Solved

I'm dealing with a big dataframe that has a number of columns I want to group by. I'd like to do something like this: output <- df %>% group_by(starts_with("GEN", ignore.case=TRUE...
Woodnote asked 28/9, 2020 at 19:0

1

Solved

I attempt to use read_csv from {readr} to read a CSV file into R. To demonstrate my real issue, I reset the argument guess_max to 5 at first (default is 1000) library(readr) formals(read_csv)$guess...
Histo asked 8/3, 2023 at 15:28

3

Solved

I would like to obtain a generic formula to arrange dataframes with a varying number of columns. For example, in this case the dataframe contains "categ_1, categ_2, points_1, points_2": ...
Reunion asked 4/10, 2022 at 6:39

1

I have a .csv file like this (except that the real .csv file has many more columns): library(tidyverse) tibble(id1 = c("a", "b"), id2 = c("c", "d"), ...
Hothouse asked 7/9, 2022 at 22:50

3

Solved

I am generating data frames of 1s and 0s as follows: library(tidyverse) library(glue) num_var <- 3 rep(list(c(0L, 1L)), num_var) %>% set_names(glue("var_{seq_len(num_var)}")) %>% ex...
Experimental asked 8/1, 2018 at 15:45

1

Solved

Suppose I have a data frame with a bunch of columns where I want to do the same NA replacement: dd <- data.frame(x = c(NA, LETTERS[1:4]), a = rep(NA_real_, 5), b = c(1:4, NA)) For example, in t...
Kempis asked 13/12, 2021 at 21:1

1

I have started to receive a warning when using selecting functions within tidyverse packages. Example: library(dplyr) set.seed(123) df = data.frame( "id" = c(rep("G1", 3), rep(...
Agamemnon asked 4/4, 2020 at 10:6

5

Solved

library(tidyverse) df <- tibble(Date = c(rep(as.Date("2020-01-01"), 3), NA), col1 = 1:4, thisCol = c(NA, 8, NA, 3), thatCol = 25:28, col999 = rep(99, 4)) #> # A tibble: 4 x 5 #> Date c...
Mcknight asked 1/5, 2020 at 14:2

1

Solved

Here's a simplified version of a function I have in a package that uses the ... argument and tidyselect to select variables: # this toy function just selects the ... variables foo <- function(d...
Rachitis asked 19/3, 2020 at 15:26

1

library(tidyverse) iris %>% as_tibble() %>% select(everything()) #> # A tibble: 150 x 5 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <dbl> <dbl> <d...
Howund asked 23/10, 2019 at 22:58

1

Solved

library(tidyverse) df <- tibble(x1 = c("A", "A", "A", "B", "B", "B"), x2 = c(NA, 8, NA, NA, NA, 5), x3 = c(3, 6, 5, 9, 1, 9)) #> # A tibble: 6 x 3 #> x1 x2 x3 #> <chr> <dbl&g...
Thermion asked 24/10, 2019 at 13:25

3

Solved

I have a helper function (say foo()) that will be run on various data frames that may or may not contain specified variables. Suppose I have library(dplyr) d1 <- data_frame(taxon=1,model=2,z=3...
Delphine asked 26/7, 2018 at 0:8

1

Solved

Let's say I have a tibble where I need to take multiple variables and mutate them into new multiple new variables. As an example, here is a simple tibble: tb <- tribble( ~x, ~y1, ~y2, ~y3, ~...
Insphere asked 21/2, 2018 at 4:21

2

Solved

I am trying to filter specific rows of my tibble using the dplyr::filter() function. Here is part of my tibble head(raw.tb): A tibble: 738 x 4 geno ind X Y <chr> <chr> <int> ...
Nanon asked 4/2, 2018 at 12:13
1

© 2022 - 2025 — McMap. All rights reserved.