Questions tagged [tidyselect]

Questions about `r` package `tidyselect` used in many functions from the `tidyverse` packages

88 questions
0
votes
1 answer

Remove string in multiple variables in R

Here is a MWE of my data from which I want to remove the string "NaN" from all the columns which contain "Med" df= data.frame(id= rep(1:5, each=1), Med1 = c("GN", "GN", "Ca", "Ca", "DM"), Med2 = c("DM", "NaN", "Mob",…
Mark Davies
  • 787
  • 5
  • 18
0
votes
1 answer

tidyselect::where() inconsistencies: where is where()?

Summary: You can do rename(A=1, B=2), can you do the same using rename_with()? my ~str_replace(... paste0()) works, I don't need to change that. But it only works for one variable at a time. Tidyselect suggests wrapping where(~str_replace...) but…
ibm
  • 744
  • 7
  • 14
0
votes
0 answers

Why does pivot_longer() only work when I specify the dataframe inside the brackets, not with pipe notation?

I was trying to rearrange a dataframe using dataframe %>% pivot_longer( ) but would keep getting errors however I tried to specify the cols argument. For instance, trying cols = (!colname) I'd get: Error: no applicable method for 'pivot_longer'…
Ellen
  • 33
  • 5
0
votes
1 answer

Select multiple date columns and convert factor variables to date

I have a data.frame with multiple columns that contain dates. At present they are recognised as "factor" class. I want to select all the columns that should be dates (there are 10 of them, they all have "Date" in their name, e.g. Date_Construc,…
Mark Davies
  • 787
  • 5
  • 18
0
votes
1 answer

Evaluation with dplyr::select does not work in my function

I am really new on dealing with evaluation issues in R. example<- data.frame(id = 1:5, pairs0 = c(1, 1, 1, 2, 2), pairs1 = c(2, 2, 1, 1, 1) ) Here is the function that I am trying to write: f…
0
votes
1 answer

Replacing mean from psych::describe for mode in dataframe

I like the summary statistics of psych::describe but I want to replace the mean with the mode but only for factor variables. How do I program Mode's output to replace setosa (or any other factor variable) I use iris for replication even though it…
ibm
  • 744
  • 7
  • 14
0
votes
0 answers

Error in mutate_at when trying to create new variables using tidyselect function when knitting R markdown

It's highly likely that I'm missing something really simple, but I cannot work out why this error is persisting in my mutate_at function. library(tidyverse) test = data.frame(diff_1 = sample(0:10, size=20, replace=TRUE), diff_2 =…
Dani
  • 161
  • 9
0
votes
0 answers

R package - tidyselect install fails

Trying to install tidyselect R pacakge on amazon linux, it fails with ERROR: lazy loading failed for package ‘tidyselect’. Please guide me on installing this package, kindly refer the below output, bash-4.2# /usr/bin/R CMD INSTALL…
0
votes
2 answers

How to prefix column names of data.frame which are !%in% list with dplyr::rename?

I have a list of column names which I do NOT want to change colsNotRename. All the other columns I do want to prefix. A way to do it in BaseR would be e.g.: xx <- data.frame(A = 1:3, B = 3:5, Unknown = c("A","B","C")) colsNotRename <-…
witek
  • 984
  • 1
  • 8
  • 25
0
votes
1 answer

How to use the new vars_rename function

I am trying to use the new suggested vars_rename() function in tidyselect after getting a soft warning that rename_at() in Dplyr is being deprecated. But, I'm having no luck getting it to work and the documentation is cryptic. It tells me to use…
Larry V
  • 143
  • 6
0
votes
1 answer

caret: 'rlang_env_get' not found

I ran library(caret) a few days ago, and it worked. Since then I've updated Rtools, and now I'm getting some errors I can't resolve through my usual methods Information below for error: > library(caret) Error: package or namespace load failed for…
Jonny Phelps
  • 2,687
  • 1
  • 11
  • 20
0
votes
2 answers

Create a matrix from all variables in each row

I have a dataframe that stores a set of vectorized matrices. That is, in each row, I have the NxM variables that correspond to the elements in the matrix. Given this dataframe, I would like to apply a function to the matrix stored in each row, and…
alberto
  • 2,625
  • 4
  • 29
  • 48
-1
votes
1 answer

helper function in R

I am trying to replace NA with 0 for some specific variables irrespective of their positions. i wrote below code, but getting some error.. data1[, starts_with("Year_")][is.na(data1[, starts_with("Year_")])] <- 0 i got the below error Error: No…
1 2 3 4 5
6